<?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[ifstream ließt letzten Buchstaben doppelt]]></title><description><![CDATA[<p>Hey folgendes Problem,<br />
ich habe eine Datei namens vokabularylist.txt, die das Programm einlesen und ausgeben soll. Das funktioniert auch soweit, nur gibt er den letzten Buchstaben doppelt aus.</p>
<pre><code class="language-cpp">// MAIN_CPP
// Programm: Zeilenlese - / schreibe Programm

#include &quot;stdafx.h&quot;

int CharToInt(char input);

using namespace std;

// Umlaute darstellen
const unsigned char Ä = static_cast&lt;unsigned char&gt;(142);
const unsigned char ä = static_cast&lt;unsigned char&gt;(132); 
const unsigned char Ö = static_cast&lt;unsigned char&gt;(153); 
const unsigned char ö = static_cast&lt;unsigned char&gt;(148); 
const unsigned char Ü = static_cast&lt;unsigned char&gt;(154); 
const unsigned char ü = static_cast&lt;unsigned char&gt;(129); 
const unsigned char ß = static_cast&lt;unsigned char&gt;(225);

int main() {
	char a;
	int iChoice;
	bool bChoice = false;

	cout &lt;&lt; &quot;&gt; 1 - Zeichen einlesen&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;&gt; 2 - Textinhalt l&quot; &lt;&lt; ö &lt;&lt; &quot;schen und neu eingeben&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;&gt; &quot;;

	// Zeichen abfragen und in eine Integer Zahl umwandeln
	// Solange nicht 1 oder 2 eingebeben wurde, iChoice nicht setzen und erneut abfragen
	while(bChoice == false) {
		// Zeichen in a speichern
		a = _getch();
		if(a == '1') {
			iChoice = CharToInt(a);
			bChoice = true; // iChoice gesetzt -&gt; while-Schleife abbrechen
		}
		else if(a == '2') {
			iChoice = CharToInt(a);
			bChoice = true; // iChoice gesetzt -&gt; while-Schleife abbrechen
		}
	}

	// Eingabe verwalten
	if(iChoice == 1) {
		system(&quot;CLS&quot;);

		const char data_name[] = &quot;vokabularylist.txt&quot;;
		char letter;
		string complete_text;

		ifstream data_in;

		data_in.open(data_name, ios::in);

		// Wenn vokabularylist.txt nicht geöffnet werden konnte...
		if(!data_in.is_open()) {
			cerr &lt;&lt; &quot;Konnte -[ vokabularylist.txt ]- nicht &quot; &lt;&lt; ö &lt;&lt; &quot;ffnen.&quot;;
			_getch();
			exit(EXIT_SUCCESS); // ... dann beenden
		}

		// Alle Zeichen einlesen solange das Ende der Datei nicht erreicht ist
		while(!data_in.eof()) {
			data_in.get(letter);
			complete_text += letter;
		}

		// Kompletten Text der Datei ausgeben
		cout &lt;&lt; complete_text;
	}
	else {
		// ...	
         }

	_getch();
	return 0;
}

int CharToInt(char input) {
	if(input == '1') { return 1; }
	else { return 2; }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/295289/ifstream-ließt-letzten-buchstaben-doppelt</link><generator>RSS for Node</generator><lastBuildDate>Sat, 15 Aug 2026 12:01:00 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/295289.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 10 Nov 2011 17:45:01 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to ifstream ließt letzten Buchstaben doppelt on Thu, 10 Nov 2011 17:45:01 GMT]]></title><description><![CDATA[<p>Hey folgendes Problem,<br />
ich habe eine Datei namens vokabularylist.txt, die das Programm einlesen und ausgeben soll. Das funktioniert auch soweit, nur gibt er den letzten Buchstaben doppelt aus.</p>
<pre><code class="language-cpp">// MAIN_CPP
// Programm: Zeilenlese - / schreibe Programm

#include &quot;stdafx.h&quot;

int CharToInt(char input);

using namespace std;

// Umlaute darstellen
const unsigned char Ä = static_cast&lt;unsigned char&gt;(142);
const unsigned char ä = static_cast&lt;unsigned char&gt;(132); 
const unsigned char Ö = static_cast&lt;unsigned char&gt;(153); 
const unsigned char ö = static_cast&lt;unsigned char&gt;(148); 
const unsigned char Ü = static_cast&lt;unsigned char&gt;(154); 
const unsigned char ü = static_cast&lt;unsigned char&gt;(129); 
const unsigned char ß = static_cast&lt;unsigned char&gt;(225);

int main() {
	char a;
	int iChoice;
	bool bChoice = false;

	cout &lt;&lt; &quot;&gt; 1 - Zeichen einlesen&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;&gt; 2 - Textinhalt l&quot; &lt;&lt; ö &lt;&lt; &quot;schen und neu eingeben&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;&gt; &quot;;

	// Zeichen abfragen und in eine Integer Zahl umwandeln
	// Solange nicht 1 oder 2 eingebeben wurde, iChoice nicht setzen und erneut abfragen
	while(bChoice == false) {
		// Zeichen in a speichern
		a = _getch();
		if(a == '1') {
			iChoice = CharToInt(a);
			bChoice = true; // iChoice gesetzt -&gt; while-Schleife abbrechen
		}
		else if(a == '2') {
			iChoice = CharToInt(a);
			bChoice = true; // iChoice gesetzt -&gt; while-Schleife abbrechen
		}
	}

	// Eingabe verwalten
	if(iChoice == 1) {
		system(&quot;CLS&quot;);

		const char data_name[] = &quot;vokabularylist.txt&quot;;
		char letter;
		string complete_text;

		ifstream data_in;

		data_in.open(data_name, ios::in);

		// Wenn vokabularylist.txt nicht geöffnet werden konnte...
		if(!data_in.is_open()) {
			cerr &lt;&lt; &quot;Konnte -[ vokabularylist.txt ]- nicht &quot; &lt;&lt; ö &lt;&lt; &quot;ffnen.&quot;;
			_getch();
			exit(EXIT_SUCCESS); // ... dann beenden
		}

		// Alle Zeichen einlesen solange das Ende der Datei nicht erreicht ist
		while(!data_in.eof()) {
			data_in.get(letter);
			complete_text += letter;
		}

		// Kompletten Text der Datei ausgeben
		cout &lt;&lt; complete_text;
	}
	else {
		// ...	
         }

	_getch();
	return 0;
}

int CharToInt(char input) {
	if(input == '1') { return 1; }
	else { return 2; }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2142990</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2142990</guid><dc:creator><![CDATA[Yoyo2000]]></dc:creator><pubDate>Thu, 10 Nov 2011 17:45:01 GMT</pubDate></item><item><title><![CDATA[Reply to ifstream ließt letzten Buchstaben doppelt on Thu, 10 Nov 2011 18:17:28 GMT]]></title><description><![CDATA[<p>eof() ist erst wahr, sobald man 1 hinters ende gelesen hab.</p>
<p>Mach also mal aus</p>
<pre><code class="language-cpp">// Alle Zeichen einlesen solange das Ende der Datei nicht erreicht ist 
         while(!data_in.eof()) { 
             data_in.get(letter); 
             complete_text += letter; 
         }
</code></pre>
<pre><code class="language-cpp">while(!data.in.eof())
{
   data_.in.get(letter);
   if(!data_in.eof())
   {
       complete_text += letter;
   }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2142995</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2142995</guid><dc:creator><![CDATA[*Q* 1]]></dc:creator><pubDate>Thu, 10 Nov 2011 18:17:28 GMT</pubDate></item><item><title><![CDATA[Reply to ifstream ließt letzten Buchstaben doppelt on Thu, 10 Nov 2011 18:02:58 GMT]]></title><description><![CDATA[<p>Oder etwas kürzer und nicht nur gegen eof sondern alle Arten von Fehlern gesichert:</p>
<pre><code class="language-cpp">while(data_.in.get(letter))
 complete_text += letter;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2143000</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2143000</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 10 Nov 2011 18:02:58 GMT</pubDate></item><item><title><![CDATA[Reply to ifstream ließt letzten Buchstaben doppelt on Thu, 10 Nov 2011 18:19:47 GMT]]></title><description><![CDATA[<p>Hey super danke funktioniert einwandfrei <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2143010</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2143010</guid><dc:creator><![CDATA[Yoyo2000]]></dc:creator><pubDate>Thu, 10 Nov 2011 18:19:47 GMT</pubDate></item><item><title><![CDATA[Reply to ifstream ließt letzten Buchstaben doppelt on Thu, 10 Nov 2011 20:38:38 GMT]]></title><description><![CDATA[<p>Nimm doch einfach, was C++ schon bietet:</p>
<pre><code class="language-cpp">{
	std::istreambuf_iterator&lt;char&gt; begin(data_in), end;
	complete_text.assign(begin, end);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2143074</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2143074</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Thu, 10 Nov 2011 20:38:38 GMT</pubDate></item><item><title><![CDATA[Reply to ifstream ließt letzten Buchstaben doppelt on Thu, 10 Nov 2011 22:49:54 GMT]]></title><description><![CDATA[<p>TyRoXx schrieb:</p>
<blockquote>
<p>Nimm doch einfach, was C++ schon bietet:</p>
<pre><code class="language-cpp">{
	std::istreambuf_iterator&lt;char&gt; begin(data_in), end;
	complete_text.assign(begin, end);
}
</code></pre>
</blockquote>
<p>wenn es wirklich nur um das Ausgeben geht, so ist auch der Container <code>complete_text</code> überflüssig:</p>
<pre><code class="language-cpp">#include &lt;fstream&gt;
#include &lt;iostream&gt;

int main()
{
    using namespace std;
    const char data_name[] = &quot;vokabularylist.txt&quot;;
    ifstream data_in( data_name ); // ios::in ist redundant, da ifstream immer eine Input-stream ist

    // ...

    // Kompletten Text der Datei ausgeben
    cout &lt;&lt; data_in.rdbuf(); // das ist alles!

    cin.get();
    return 0;
}
</code></pre>
<p>Yoyo2000 schrieb:</p>
<blockquote>
<p>.. Das funktioniert auch soweit, nur gibt er den letzten Buchstaben doppelt aus.</p>
<pre><code class="language-cpp">while(!data_in.eof()) {
</code></pre>
</blockquote>
<p>siehe dazu den <a href="http://www.c-plusplus.net/forum/p2042572#2042572" rel="nofollow">while(!EOF)-Virus</a>.</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2143111</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2143111</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Thu, 10 Nov 2011 22:49:54 GMT</pubDate></item><item><title><![CDATA[Reply to ifstream ließt letzten Buchstaben doppelt on Thu, 10 Nov 2011 22:54:49 GMT]]></title><description><![CDATA[<p>Wieso lässt sich ein Buffer ausgeben?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2143114</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2143114</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Thu, 10 Nov 2011 22:54:49 GMT</pubDate></item><item><title><![CDATA[Reply to ifstream ließt letzten Buchstaben doppelt on Thu, 10 Nov 2011 23:12:07 GMT]]></title><description><![CDATA[<p>314159265358979 schrieb:</p>
<blockquote>
<p>Wieso lässt sich ein Buffer ausgeben?</p>
</blockquote>
<p>Weil's der C++-Standard so vorgibt - siehe [lib.ostream.inserters] oder <a href="http://www.cplusplus.com/reference/iostream/ostream/operator%3C%3C/" rel="nofollow">ostream&amp; operator&lt;&lt; (streambuf* sb);</a>.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2143116</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2143116</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Thu, 10 Nov 2011 23:12:07 GMT</pubDate></item><item><title><![CDATA[Reply to ifstream ließt letzten Buchstaben doppelt on Thu, 10 Nov 2011 23:14:32 GMT]]></title><description><![CDATA[<p>Klingt irgendwie ziemlich pervers. Einen Buffer ausgeben? WTF.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2143118</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2143118</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Thu, 10 Nov 2011 23:14:32 GMT</pubDate></item></channel></rss>