<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Problem mit ofstream und ifstream]]></title><description><![CDATA[<p>Hallo,<br />
ich mache mich gerade mit ofstream und ifstream vertraut, aber irgendwie klappt es noch nicht so richtig. Das Problem ist, dass nicht die richtige Variable wieder ausgelesen wird, bzw nicht den richtigen Wert hat.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string.h&gt;

using namespace std;

int main()
{
	int size_min, size_max;
	int weight_min, weight_max;
	char file[30];

	cout &lt;&lt; &quot;Name of file: &quot;;
	cin &gt;&gt; file;

	strcat(file, &quot;.blub&quot;);

	ofstream Output(file, ios::binary);
	Output.write((char*) &amp;file, sizeof(file));

	cout &lt;&lt; &quot;Minimal and maximal size&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;Min: &quot;;
	cin &gt;&gt; size_min;
	cout &lt;&lt; &quot;Max: &quot;;
	cin &gt;&gt; size_max;

	Output.write((char*) &amp;size_min, sizeof(size_min));
	Output.write((char*) &amp;size_max, sizeof(size_max));

	cout &lt;&lt; &quot;Minimal and maximal weight&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;Min: &quot;;
	cin &gt;&gt; weight_min;
	cout &lt;&lt; &quot;Max: &quot;;
	cin &gt;&gt; weight_max;

	Output.write((char*) &amp;weight_min, sizeof(weight_min));
	Output.write((char*) &amp;weight_max, sizeof(weight_max));

	Output.close();

	size_max = 0;

	ifstream Input(file);
	Input.read((char*) &amp;size_max, sizeof(size_max));
	Input.close();

	cout &lt;&lt; size_max;

	return 0;
}
</code></pre>
<p>Es kommt halt irgendein Wert raus, der aber absolut nix mit den gespeicherten Werten zu tun. Hoffe ihr könnt mir helfen.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/242272/problem-mit-ofstream-und-ifstream</link><generator>RSS for Node</generator><lastBuildDate>Mon, 21 Sep 2026 02:45:32 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/242272.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 01 Jun 2009 20:42:29 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit ofstream und ifstream on Mon, 01 Jun 2009 20:42:29 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich mache mich gerade mit ofstream und ifstream vertraut, aber irgendwie klappt es noch nicht so richtig. Das Problem ist, dass nicht die richtige Variable wieder ausgelesen wird, bzw nicht den richtigen Wert hat.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string.h&gt;

using namespace std;

int main()
{
	int size_min, size_max;
	int weight_min, weight_max;
	char file[30];

	cout &lt;&lt; &quot;Name of file: &quot;;
	cin &gt;&gt; file;

	strcat(file, &quot;.blub&quot;);

	ofstream Output(file, ios::binary);
	Output.write((char*) &amp;file, sizeof(file));

	cout &lt;&lt; &quot;Minimal and maximal size&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;Min: &quot;;
	cin &gt;&gt; size_min;
	cout &lt;&lt; &quot;Max: &quot;;
	cin &gt;&gt; size_max;

	Output.write((char*) &amp;size_min, sizeof(size_min));
	Output.write((char*) &amp;size_max, sizeof(size_max));

	cout &lt;&lt; &quot;Minimal and maximal weight&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;Min: &quot;;
	cin &gt;&gt; weight_min;
	cout &lt;&lt; &quot;Max: &quot;;
	cin &gt;&gt; weight_max;

	Output.write((char*) &amp;weight_min, sizeof(weight_min));
	Output.write((char*) &amp;weight_max, sizeof(weight_max));

	Output.close();

	size_max = 0;

	ifstream Input(file);
	Input.read((char*) &amp;size_max, sizeof(size_max));
	Input.close();

	cout &lt;&lt; size_max;

	return 0;
}
</code></pre>
<p>Es kommt halt irgendein Wert raus, der aber absolut nix mit den gespeicherten Werten zu tun. Hoffe ihr könnt mir helfen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1719315</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1719315</guid><dc:creator><![CDATA[Cloppy]]></dc:creator><pubDate>Mon, 01 Jun 2009 20:42:29 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit ofstream und ifstream on Mon, 01 Jun 2009 21:00:13 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">Output.write((char*) &amp;file, sizeof(file));
</code></pre>
<p>Du schreibst am Anfang den Dateinamen in die Datei und zum Schluss liest du ganz am Anfang aus. Deine Werte haben also sehr wohl etwas mit den gespeicherten Werten zu tun ;).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1719322</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1719322</guid><dc:creator><![CDATA[blub* 0]]></dc:creator><pubDate>Mon, 01 Jun 2009 21:00:13 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit ofstream und ifstream on Mon, 01 Jun 2009 21:24:01 GMT]]></title><description><![CDATA[<p>oh okay...<br />
Wie kann ich denn den variablennamen in verbindung mit dessen wert in eine datei schreiben, sodass ich irgendeine variable irgendwo in der datei wieder auslesen kann?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1719329</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1719329</guid><dc:creator><![CDATA[Cloppy]]></dc:creator><pubDate>Mon, 01 Jun 2009 21:24:01 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit ofstream und ifstream on Mon, 01 Jun 2009 22:01:52 GMT]]></title><description><![CDATA[<p>Cloppy schrieb:</p>
<blockquote>
<p>oh okay...<br />
Wie kann ich denn den variablennamen in verbindung mit dessen wert in eine datei schreiben, sodass ich irgendeine variable irgendwo in der datei wieder auslesen kann?</p>
</blockquote>
<p>Dazu brauchst du ein Serialisierungsformat. Such mal nach Serialisierung oder schau dir <a href="http://www.boost.org/doc/libs/1_39_0/libs/serialization/doc/index.html" rel="nofollow">Boost.Serialization</a> an.</p>
<p>Was du machst ist einfach nur Byte für Byte schreiben und dann über den <code>ifstream</code> Byte für Byte lesen. Mehr wird da nicht gemacht. Die Variablennamen sind da völlig irrelevant.</p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1719345</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1719345</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Mon, 01 Jun 2009 22:01:52 GMT</pubDate></item></channel></rss>