<?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[was mache ich falsch bei fstream]]></title><description><![CDATA[<p>in laufwerk D liegt die textdatei test.txt<br />
lesen tut es richtig, aber es schreibt nicht, wenn ich die lese operation fs &gt;&gt; s auskommentiere, dann wird alte text in test.txt ueberschrieben.<br />
wieso funktioniert es nicht lesen und schreiben zusammen?<br />
ist das etwa gemeint, lesen oder schreiben?</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;

using namespace std;

int main() {
	string s;
	fstream fs( &quot;D:\\test.txt&quot;, ios::in | ios::out );
	fs &gt;&gt; s;
	cout &lt;&lt; s;
	fs &lt;&lt; &quot;new string&quot;;
	fs.close();
	system( &quot;pause&quot; );
	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/270417/was-mache-ich-falsch-bei-fstream</link><generator>RSS for Node</generator><lastBuildDate>Sun, 23 Aug 2026 08:56:20 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/270417.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 12 Jul 2010 09:39:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to was mache ich falsch bei fstream on Mon, 12 Jul 2010 09:39:56 GMT]]></title><description><![CDATA[<p>in laufwerk D liegt die textdatei test.txt<br />
lesen tut es richtig, aber es schreibt nicht, wenn ich die lese operation fs &gt;&gt; s auskommentiere, dann wird alte text in test.txt ueberschrieben.<br />
wieso funktioniert es nicht lesen und schreiben zusammen?<br />
ist das etwa gemeint, lesen oder schreiben?</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;

using namespace std;

int main() {
	string s;
	fstream fs( &quot;D:\\test.txt&quot;, ios::in | ios::out );
	fs &gt;&gt; s;
	cout &lt;&lt; s;
	fs &lt;&lt; &quot;new string&quot;;
	fs.close();
	system( &quot;pause&quot; );
	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1924928</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1924928</guid><dc:creator><![CDATA[JnZn558]]></dc:creator><pubDate>Mon, 12 Jul 2010 09:39:56 GMT</pubDate></item><item><title><![CDATA[Reply to was mache ich falsch bei fstream on Mon, 12 Jul 2010 10:05:07 GMT]]></title><description><![CDATA[<p>Schau dir doch mal <a href="http://www.cplusplus.com/reference/iostream/fstream/fstream/" rel="nofollow">http://www.cplusplus.com/reference/iostream/fstream/fstream/</a> an und den Modus std::ios::app (steht für append, anhängen)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1924938</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1924938</guid><dc:creator><![CDATA[Anhänger]]></dc:creator><pubDate>Mon, 12 Jul 2010 10:05:07 GMT</pubDate></item><item><title><![CDATA[Reply to was mache ich falsch bei fstream on Mon, 12 Jul 2010 10:05:54 GMT]]></title><description><![CDATA[<p>Für kombinierte Lese/Schreibaktionen auf den selben Stream verweist der C++-Standard auf den C-Standard, und dieser sagte:</p>
<p>ISO/IEC 9899:1990 schrieb:</p>
<blockquote>
<p>When a file is opened with update mode ('+' as the second or third character in the above list of mode argument values), both input and output may be performed on the associated stream. However, output shall not be directly followed by input without an intervening call to the fflush function or to a file positioning function (fseek, fsetpos,or rewind), and input shall not be directly followed by output without an intervening call to a file positioning function, unless the input operation encounters end-of-file. Opening (or creating) a text file with update mode may instead open (or create) a binary stream in some implementations.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1924939</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1924939</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Mon, 12 Jul 2010 10:05:54 GMT</pubDate></item><item><title><![CDATA[Reply to was mache ich falsch bei fstream on Mon, 12 Jul 2010 10:58:51 GMT]]></title><description><![CDATA[<p>Tachyon schrieb:</p>
<blockquote>
<p>Für kombinierte Lese/Schreibaktionen auf den selben Stream verweist der C++-Standard auf den C-Standard, und dieser sagte:</p>
<p>ISO/IEC 9899:1990 schrieb:</p>
<blockquote>
<p>When a file is opened with update mode ('+' as the second or third character in the above list of mode argument values), both input and output may be performed on the associated stream. However, output shall not be directly followed by input without an intervening call to the fflush function or to a file positioning function (fseek, fsetpos,or rewind), and input shall not be directly followed by output without an intervening call to a file positioning function, unless the input operation encounters end-of-file. Opening (or creating) a text file with update mode may instead open (or create) a binary stream in some implementations.</p>
</blockquote>
</blockquote>
<p>ich glaub das was du meist ist, C type FILE, not C++, wenn ich mich da nicht taeusche,</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;

using namespace std;

int main() {
	string s;
	fstream fs( &quot;D:\\test.txt&quot;, ios::in | ios::out );
	fs &gt;&gt; s;
	cout &lt;&lt; s;
	fs.flush();
	fs &lt;&lt; &quot;new string&quot;;
	fs.close();
	system( &quot;pause&quot; );
	return 0;
}
</code></pre>
<p>so funktioniert es auch nicht</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1924962</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1924962</guid><dc:creator><![CDATA[JnZn558]]></dc:creator><pubDate>Mon, 12 Jul 2010 10:58:51 GMT</pubDate></item><item><title><![CDATA[Reply to was mache ich falsch bei fstream on Mon, 12 Jul 2010 13:24:04 GMT]]></title><description><![CDATA[<p>kann mir niemand weiterhelfen oder was</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1925040</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1925040</guid><dc:creator><![CDATA[JnZn558]]></dc:creator><pubDate>Mon, 12 Jul 2010 13:24:04 GMT</pubDate></item><item><title><![CDATA[Reply to was mache ich falsch bei fstream on Mon, 12 Jul 2010 14:00:51 GMT]]></title><description><![CDATA[<p>Probiers mal so:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;

using namespace std;

int main() 
{
    string s;
    fstream fs( &quot;D:\\test.txt&quot;, ios::in | ios::out );
    fs &gt;&gt; s;
    cout &lt;&lt; s &lt;&lt; '\n';
    fs.seekp(0, std::ios_base::end);
    fs &lt;&lt; &quot;new string\n&quot;;
    return 0;
}
</code></pre>
<p>Und das oben zitierte gilt auch für <code>std::fstream</code> . Wie gesagt, der C++-Standard verweist an der Stelle auf den C-Standard.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1925051</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1925051</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Mon, 12 Jul 2010 14:00:51 GMT</pubDate></item><item><title><![CDATA[Reply to was mache ich falsch bei fstream on Mon, 12 Jul 2010 17:55:24 GMT]]></title><description><![CDATA[<p>Tachyon schrieb:</p>
<blockquote>
<p>Probiers mal so:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;

using namespace std;

int main() 
{
    string s;
    fstream fs( &quot;D:\\test.txt&quot;, ios::in | ios::out );
    fs &gt;&gt; s;
    cout &lt;&lt; s &lt;&lt; '\n';
    fs.seekp(0, std::ios_base::end);
    fs &lt;&lt; &quot;new string\n&quot;;
    return 0;
}
</code></pre>
<p>Und das oben zitierte gilt auch für <code>std::fstream</code> . Wie gesagt, der C++-Standard verweist an der Stelle auf den C-Standard.</p>
</blockquote>
<p>geht net, funz nicht, wird nix geschrieben</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1925191</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1925191</guid><dc:creator><![CDATA[JnZn558]]></dc:creator><pubDate>Mon, 12 Jul 2010 17:55:24 GMT</pubDate></item><item><title><![CDATA[Reply to was mache ich falsch bei fstream on Tue, 13 Jul 2010 06:49:12 GMT]]></title><description><![CDATA[<p>JnZn558 schrieb:</p>
<blockquote>
<p>[...]</p>
</blockquote>
<p>Hmm, bei mir geht geht das. Vor Programmaufruf in test.txt:<br />
<code>Hallo</code></p>
<p>Nach Programmaufruf in test.txt:<br />
`Hallo</p>
<p>new string`</p>
<p>Ausgabe:<br />
<code>Hallo</code></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1925355</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1925355</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Tue, 13 Jul 2010 06:49:12 GMT</pubDate></item><item><title><![CDATA[Reply to was mache ich falsch bei fstream on Tue, 13 Jul 2010 09:58:32 GMT]]></title><description><![CDATA[<p>hab unter xp auch getestet, funz auch net</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1925447</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1925447</guid><dc:creator><![CDATA[JnZn558]]></dc:creator><pubDate>Tue, 13 Jul 2010 09:58:32 GMT</pubDate></item><item><title><![CDATA[Reply to was mache ich falsch bei fstream on Tue, 13 Jul 2010 10:04:34 GMT]]></title><description><![CDATA[<p>JnZn558: Vielleicht kannst du mir auch kurz helfen. Ich hab da ein Programm geschrieben, das soll ungefähr dasselbe machen wie deins. Aber es funktioniert einfach nicht!</p>
<p>Hast du denn d:\test.txt schon erstellt und steht da auch artig was drin?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1925457</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1925457</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Tue, 13 Jul 2010 10:04:34 GMT</pubDate></item><item><title><![CDATA[Reply to was mache ich falsch bei fstream on Tue, 13 Jul 2010 11:20:01 GMT]]></title><description><![CDATA[<p>ja, es ist ein inhalt drin.<br />
mein eigentlichen vorhaben, ist den inhalt zu veraendern</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1925522</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1925522</guid><dc:creator><![CDATA[JnZn558]]></dc:creator><pubDate>Tue, 13 Jul 2010 11:20:01 GMT</pubDate></item><item><title><![CDATA[Reply to was mache ich falsch bei fstream on Tue, 13 Jul 2010 11:31:43 GMT]]></title><description><![CDATA[<p>Findest du nicht, dass &quot;geht net, funz nicht, wird nix geschrieben&quot; ziemlich ungenau ist? Was machst du genau? Wie sehen die Vorbedingungen aus? Meldet der Compiler was? Was steht in der Datei?</p>
<p>Im Moment sieht es so aus, dass der von Tachyon gepostete Code genau das macht, was er tun sollte. Wenn du also nicht mehr sagst als &quot;geht nicht&quot;, kann ich dir nicht weiterhelfen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1925532</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1925532</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Tue, 13 Jul 2010 11:31:43 GMT</pubDate></item><item><title><![CDATA[Reply to was mache ich falsch bei fstream on Tue, 13 Jul 2010 13:36:15 GMT]]></title><description><![CDATA[<p>Michael E. schrieb:</p>
<blockquote>
<p>Findest du nicht, dass &quot;geht net, funz nicht, wird nix geschrieben&quot; ziemlich ungenau ist? Was machst du genau? Wie sehen die Vorbedingungen aus? Meldet der Compiler was? Was steht in der Datei?</p>
<p>Im Moment sieht es so aus, dass der von Tachyon gepostete Code genau das macht, was er tun sollte. Wenn du also nicht mehr sagst als &quot;geht nicht&quot;, kann ich dir nicht weiterhelfen.</p>
</blockquote>
<p>in der textdatei steht irgendein beispiel text, mein eigentlichen vorhaben is ein text auslesen und inhalt veraendern und wieder in die textdatei schreiben, jedoch funktioniert das schreiben nicht, und das ist mein problem.</p>
<p>es wird richtig compiliert und kein fehler wird produziert, nur die textdatei wird ueberhaupt nix veraendert, ( also keine neuen inhalt reingeschrieben ).</p>
<p>ist es soweit verstaendlich??</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1925602</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1925602</guid><dc:creator><![CDATA[JnZn558]]></dc:creator><pubDate>Tue, 13 Jul 2010 13:36:15 GMT</pubDate></item><item><title><![CDATA[Reply to was mache ich falsch bei fstream on Tue, 15 Feb 2011 21:32:36 GMT]]></title><description><![CDATA[<p>Hallo, ich muss das hier noch mal hoch holen. Ich habe genau das gleiche Problem und weiß auch nicht was ich noch machen soll. Hat einer ne neue Idee?</p>
<pre><code>#include &lt;fstream&gt;

fstream file;
file.open (myPath.c_str(), ios::in | ios::out | ios::binary);

string sLine;

//configdatei zeilenweise einlesen
while(getline(file, sLine))
{
   //Änderungen machen in der richtigen Zeile
}

//das funktioniert beides nicht
file.flush();
file.seekp(0, std::ios_base::end); 

//datei schreiben hier soll jetzt einfach nur mal test rein
file.write (&quot;test&quot;,4);
file.close();
	}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2021592</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2021592</guid><dc:creator><![CDATA[TheRave]]></dc:creator><pubDate>Tue, 15 Feb 2011 21:32:36 GMT</pubDate></item><item><title><![CDATA[Reply to was mache ich falsch bei fstream on Wed, 16 Feb 2011 18:35:32 GMT]]></title><description><![CDATA[<p>Hallo so geht Lesen UND Schreiben gleichzeitig:</p>
<pre><code class="language-cpp">#include&lt;fstream&gt;
#include&lt;iostream&gt;

using namespace std;

// Lesen und Schreiben auf *einer* Datei

int main() {
    // Datei anlegen
    fstream filestream(&quot;fstream2.dat&quot;, ios::out | ios::trunc);
    filestream.close();            // leere Datei existiert jetzt
    int i;                 // Hilfsvariable

    // Datei zum Lesen und Schreiben öffnen
    filestream.open(&quot;fstream2.dat&quot;, ios::in | ios::out);
    // schreiben
    for(i = 0; i &lt; 20; ++i) {
      filestream &lt;&lt; i &lt;&lt; ' ';         // kein EOF direkt nach der letzten Zahl
    }
    filestream &lt;&lt; endl;

    // lesen
    filestream.seekg(0);               // Anfang suchen
    while(filestream.good()) {
       filestream &gt;&gt; i;                // lesen
       if(filestream.good()) {
          cout &lt;&lt; i &lt;&lt; ' ';    // Kontrollausgabe
       }
       else {
          cout &lt;&lt; endl &lt;&lt; &quot;Dateiende erreicht (oder Lesefehler)&quot;;
       }
    }
    cout &lt;&lt; endl;
    filestream.clear();                // EOF-Status löschen
    filestream.seekp(5);               // Position 5 suchen

    filestream &lt;&lt; &quot;neuer Text &quot;;       // ab Pos. 5 überschreiben
    filestream.seekg(0);               // Anfang suchen
    char buf[100];
    filestream.getline(buf,100);       // Zeile lesen
    cout &lt;&lt; buf &lt;&lt; endl;       // Kontrollausgabe
}
</code></pre>
<p>Statt trunc kann man auch app nehmen, wenn die datei nicht geleert werden soll.<br />
Ausgabe des Programms:</p>
<pre><code>0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 
Dateiende erreicht (oder Lesefehler)
0 1 2neuer Text 8 9 10 11 12 13 14 15 16 17 18 19
</code></pre>
<p>Man beachte das mittenrein geschriebene &quot;neuerText&quot;.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2021954</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2021954</guid><dc:creator><![CDATA[fstream_oder_was]]></dc:creator><pubDate>Wed, 16 Feb 2011 18:35:32 GMT</pubDate></item><item><title><![CDATA[Reply to was mache ich falsch bei fstream on Wed, 16 Feb 2011 20:56:29 GMT]]></title><description><![CDATA[<p>Dankeschön, das EOF Status löschen hat gefehlt.</p>
<pre><code>filestream.clear();
</code></pre>
<p>file.flush() macht wohl nicht das gleiche wie fflush() wie es weiter oben in der Beschreibung stand. fflush() geht hier aber auch nicht, das erwartet einen pointer auf ein file und keinen fstream.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2022017</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2022017</guid><dc:creator><![CDATA[TheRave]]></dc:creator><pubDate>Wed, 16 Feb 2011 20:56:29 GMT</pubDate></item><item><title><![CDATA[Reply to was mache ich falsch bei fstream on Wed, 16 Feb 2011 21:01:23 GMT]]></title><description><![CDATA[<p>Ja, <code>fflush()</code> ist auch C, die Streams sind hingegen C++.</p>
<p>Statt <code>open()</code> kannst du gleich den Konstruktor verwenden. <code>close()</code> brauchst du nicht, das geschieht im Destruktor. Und generell würde ich nicht binäres und textuelles Lesen/Schreiben in der selben Datei mischen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2022019</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2022019</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Wed, 16 Feb 2011 21:01:23 GMT</pubDate></item></channel></rss>