<?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[Eingabepuffer leeren]]></title><description><![CDATA[<p>Hallo miteinander,</p>
<p>beim Versuch einen Reaktionstest in ANSI C++ für die Konsole zu schreiben, stieß ich auf ein Problem.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;stdlib.h&gt;
#include &lt;ctime&gt;

using namespace std;

int main(int argc, char *argv[])
{
  cout &lt;&lt; endl;
  char c;
  int n;
  double diff, best;
  clock_t c1, c2;
  char cstr[256];

  best = 0.5;

  while(true)
  {
    cout &lt;&lt; &quot;CLOCK STARTED...&quot; &lt;&lt; endl;

    n = (rand() % 10 + 5) * CLOCKS_PER_SEC;
    c1 = clock();
    while(n &gt; clock() - c1)
    {}

    cout &lt;&lt; &quot;PRESS ENTER NOW!&quot;;

    // Wie leert man cin?

    c1 = clock();
    cin.get(c);
    c2 = clock();
    diff = (double(c2 - c1) / CLOCKS_PER_SEC);
    cout &lt;&lt; &quot;reaction time: &quot; &lt;&lt; diff &lt;&lt; &quot;s&quot; &lt;&lt; endl;

    ...

    cout &lt;&lt; endl;
  }
  return 0;
}
</code></pre>
<p>Wenn man bei diesem Programm noch bevor <code>PRESS ENTER NOW!</code> erscheint die Eingabetaste betätigt, dann scheint die Reaktionszeit <code>0s</code> zu sein. Wie kann man also den Eingabepuffer leeren?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/270676/eingabepuffer-leeren</link><generator>RSS for Node</generator><lastBuildDate>Sat, 29 Aug 2026 18:02:07 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/270676.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 16 Jul 2010 10:53:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Eingabepuffer leeren on Fri, 16 Jul 2010 10:53:42 GMT]]></title><description><![CDATA[<p>Hallo miteinander,</p>
<p>beim Versuch einen Reaktionstest in ANSI C++ für die Konsole zu schreiben, stieß ich auf ein Problem.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;stdlib.h&gt;
#include &lt;ctime&gt;

using namespace std;

int main(int argc, char *argv[])
{
  cout &lt;&lt; endl;
  char c;
  int n;
  double diff, best;
  clock_t c1, c2;
  char cstr[256];

  best = 0.5;

  while(true)
  {
    cout &lt;&lt; &quot;CLOCK STARTED...&quot; &lt;&lt; endl;

    n = (rand() % 10 + 5) * CLOCKS_PER_SEC;
    c1 = clock();
    while(n &gt; clock() - c1)
    {}

    cout &lt;&lt; &quot;PRESS ENTER NOW!&quot;;

    // Wie leert man cin?

    c1 = clock();
    cin.get(c);
    c2 = clock();
    diff = (double(c2 - c1) / CLOCKS_PER_SEC);
    cout &lt;&lt; &quot;reaction time: &quot; &lt;&lt; diff &lt;&lt; &quot;s&quot; &lt;&lt; endl;

    ...

    cout &lt;&lt; endl;
  }
  return 0;
}
</code></pre>
<p>Wenn man bei diesem Programm noch bevor <code>PRESS ENTER NOW!</code> erscheint die Eingabetaste betätigt, dann scheint die Reaktionszeit <code>0s</code> zu sein. Wie kann man also den Eingabepuffer leeren?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927142</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927142</guid><dc:creator><![CDATA[ccc]]></dc:creator><pubDate>Fri, 16 Jul 2010 10:53:42 GMT</pubDate></item><item><title><![CDATA[Reply to Eingabepuffer leeren on Fri, 16 Jul 2010 11:11:52 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">cin.flush();
</code></pre>
<p>Lg freeG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927153</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927153</guid><dc:creator><![CDATA[fr33g]]></dc:creator><pubDate>Fri, 16 Jul 2010 11:11:52 GMT</pubDate></item><item><title><![CDATA[Reply to Eingabepuffer leeren on Fri, 16 Jul 2010 11:18:52 GMT]]></title><description><![CDATA[<p>fr33g schrieb:</p>
<blockquote>
<pre><code class="language-cpp">cin.flush();
</code></pre>
</blockquote>
<p>Bitte lieber nachdenken bevor geschrieben wird -- <code>.flush()</code> gibt's nur für <code>ostream</code> -Objekte, nicht für <code>istream</code> -Objekte!<br />
<a href="http://www.cplusplus.com/reference/iostream/istream/" rel="nofollow">http://www.cplusplus.com/reference/iostream/istream/</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927161</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927161</guid><dc:creator><![CDATA[ccc]]></dc:creator><pubDate>Fri, 16 Jul 2010 11:18:52 GMT</pubDate></item><item><title><![CDATA[Reply to Eingabepuffer leeren on Fri, 16 Jul 2010 11:22:24 GMT]]></title><description><![CDATA[<p>fr33g schrieb:</p>
<blockquote>
<pre><code class="language-cpp">cin.flush();
</code></pre>
<p>Lg freeG</p>
</blockquote>
<pre><code>‘struct std::istream’ has no member named ‘flush’
</code></pre>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/30695">@ccc</a>: Kann dir leider auch nicht weiterhelfen, denn alle Methoden den Eingabepuffer zu leeren sind eher Behelfsmittel, da C++ die Eingabe nur als eine lange Reihe von Zeichen ansieht, ohne irgendwelche Informationen darüber in welchem Puffer sie gerade sind, wann sie eingegeben wurden oder woher sie kommen. Beispielsweise könnte man jedes C++ Programm ohne jede Änderung mit einer Datei anstatt einer Tastatur als Eingabe benutzen, dies ist sogar eine sehr verbreitete Methode. Und wie du dir sicherlich denken kannst, macht &quot;Eingabepuffer leeren&quot; bei einer Datei keinen Sinn, weil gar nicht klar ist was ein Eingabepuffer sein soll.<br />
Wenn du wirklich sicher gehen willst, dass die Eingabe von der Tastatur kommt, empfehle ich dir eine Konsolenbibliothek zu benutzen. Diese bieten dann natürlich auch Methoden um den Puffer zu leeren, denn wenn man weiß, dass die Eingabe von der Tastatur kommt, macht der Begriff &quot;Eingabepuffer&quot; auch einen Sinn. Leider sind die verschiedenen Konsolen zueinander ziemlich inkompatibel, weswegen du dich mit der Bibliothek auch auf ein System festlegen würdest. Eine verbreitete Bibliothek für POSIX-Konsolen ist beispielsweise <em>ncurses</em>.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927166</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927166</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Fri, 16 Jul 2010 11:22:24 GMT</pubDate></item><item><title><![CDATA[Reply to Eingabepuffer leeren on Fri, 16 Jul 2010 11:27:27 GMT]]></title><description><![CDATA[<p>ccc schrieb:</p>
<blockquote>
<p>fr33g schrieb:</p>
<blockquote>
<pre><code class="language-cpp">cin.flush();
</code></pre>
</blockquote>
<p>Bitte lieber nachdenken bevor geschrieben wird -- <code>.flush()</code> gibt's nur für <code>ostream</code> -Objekte, nicht für <code>istream</code> -Objekte!<br />
<a href="http://www.cplusplus.com/reference/iostream/istream/" rel="nofollow">http://www.cplusplus.com/reference/iostream/istream/</a></p>
</blockquote>
<p>Ups, ja sorry wär in dem Fall besser gewesen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<p>Lg freeG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927180</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927180</guid><dc:creator><![CDATA[fr33g]]></dc:creator><pubDate>Fri, 16 Jul 2010 11:27:27 GMT</pubDate></item><item><title><![CDATA[Reply to Eingabepuffer leeren on Fri, 16 Jul 2010 11:40:55 GMT]]></title><description><![CDATA[<p>MetaInfo:<br />
1.) googel: c++ cin<br />
2.) click auf ersten Treffer : <a href="http://www.cplusplus.com/reference/iostream/cin/" rel="nofollow">http://www.cplusplus.com/reference/iostream/cin/</a><br />
3.) lies:</p>
<blockquote>
<p>cin is an object of class istream that represents the standard input stream. I</p>
</blockquote>
<p>4.) click auf istream, scroll down, lies methoden</p>
<blockquote>
<p>ignore Extract and discard characters (public member functions)</p>
</blockquote>
<p>5.) click ignore, scroll down, lies und schau den Code an</p>
<p>Mach eigenen code:<br />
Ignoriere ganz viele Zeichen vor deinen Textausgaben.<br />
Mach deine Textausgabe 1. Warte ... vor Textausgabe prüfe of Taste gedrückt wurde, wenn ja BEEEEEEEEEEEEEEEEEEEEEEEP, Verloren.<br />
Mach deine 2. Textausgabe, warte auf Taste und rechne Zeit</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927186</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927186</guid><dc:creator><![CDATA[padreigh]]></dc:creator><pubDate>Fri, 16 Jul 2010 11:40:55 GMT</pubDate></item><item><title><![CDATA[Reply to Eingabepuffer leeren on Fri, 16 Jul 2010 11:51:14 GMT]]></title><description><![CDATA[<p>padreigh schrieb:</p>
<blockquote>
<p>...istream::ignore()...</p>
</blockquote>
<p>Keine gute Idee:</p>
<p><a href="http://www.cplusplus.com" rel="nofollow">www.cplusplus.com</a> schrieb:</p>
<blockquote>
<p>`istream&amp;  ignore ( streamsize n = 1, int delim = EOF );</p>
<p>`<br />
Extract and discard characters<br />
Extracts characters from the input sequence and discards them.</p>
<p><strong>The extraction ends when n characters have been extracted and discarded or when the character delim is found, whichever comes first.</strong> In the latter case, the delim character itself is also extracted.</p>
</blockquote>
<p>Hervorhebung durch mich. Der Satz heißt:</p>
<p>Wenn man ignore macht und es sind nicht genug Zeichen zum ignorieren da, dann wird solange gewartet bis so viele Zeichen eingegeben wurden.</p>
<p>Wenn man ignore macht und man gibt das newline-Zeichen '\n' (entspricht Enter-Taste) als Trennzeichen an, dann wird (sofern vorhanden) zwar das nächste newline-Zeichen ingoriert (sofern vorhanden, ansonsten wird gewartet), das nützt aber herzlich wenig wenn der Benutzer zweimal Enter drückt, denn dann wird nur das erste Drücken verworfen.</p>
<p>Testprogramm:</p>
<pre><code class="language-cpp">#include&lt;iostream&gt;
using namespace std;

int main()
{
  int a,b;
  cout&lt;&lt;&quot;A?&quot;&lt;&lt;endl;
  cin&gt;&gt;a;
  cin.ignore(20);
  cout&lt;&lt;&quot;B?&quot;&lt;&lt;endl;
  cin&gt;&gt;b;
  cout&lt;&lt;&quot;A: &quot;&lt;&lt;a&lt;&lt;&quot; B: &quot;&lt;&lt;b&lt;&lt;endl;
}
</code></pre>
<p>Man achte darauf, dass nach der Abfrage von A das Programm stoppt und erstmal 20 Zeichen eingegeben werden müssen, bevor nach B gefragt wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927197</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927197</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Fri, 16 Jul 2010 11:51:14 GMT</pubDate></item><item><title><![CDATA[Reply to Eingabepuffer leeren on Fri, 16 Jul 2010 12:20:08 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Keine gute Idee:</p>
</blockquote>
<p>Jo stimmt, mein Fehler.</p>
<p>Mit while(1) { peek(); if (good()) ignore(1); else break;} klappts auch nicht.<br />
Härtere Nuß als ich dachte <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927217</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927217</guid><dc:creator><![CDATA[padreigh]]></dc:creator><pubDate>Fri, 16 Jul 2010 12:20:08 GMT</pubDate></item><item><title><![CDATA[Reply to Eingabepuffer leeren on Fri, 16 Jul 2010 12:28:39 GMT]]></title><description><![CDATA[<p>padreigh schrieb:</p>
<blockquote>
<p>SeppJ schrieb:</p>
<blockquote>
<p>Keine gute Idee:</p>
</blockquote>
<p>Jo stimmt, mein Fehler.</p>
<p>Mit while(1) { peek(); if (good()) ignore(1); else break;} klappts auch nicht.<br />
Härtere Nuß als ich dachte <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
</blockquote>
<p>Wie schon gesagt, liegt dass daran, dass das einfach nicht vorgesehen ist. Das Modell der Eingabestreams ist nur eine lange Kette von Zeichen ohne jede Zusatzinformation. Die ganze technische Umsetzung mit eventuellen Pufferspeichern ist wegabstrahiert und mit Standardmitteln nicht zugänglich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927223</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927223</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Fri, 16 Jul 2010 12:28:39 GMT</pubDate></item><item><title><![CDATA[Reply to Eingabepuffer leeren on Fri, 16 Jul 2010 12:38:59 GMT]]></title><description><![CDATA[<p>Ist zwar nicht C++ aber vielleicht hilfts ja weiter:</p>
<p>fflush (stdin)<br />
Zumindest unter Windows löscht man damit den Eingabepuffer.<br />
<a href="http://msdn.microsoft.com/en-us/library/9yky46tz%28VS.71%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/9yky46tz(VS.71).aspx</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927228</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927228</guid><dc:creator><![CDATA[Source2702]]></dc:creator><pubDate>Fri, 16 Jul 2010 12:38:59 GMT</pubDate></item><item><title><![CDATA[Reply to Eingabepuffer leeren on Fri, 16 Jul 2010 12:53:14 GMT]]></title><description><![CDATA[<blockquote>
<p>&gt; Wie schon gesagt, liegt dass daran, dass das einfach nicht vorgesehen ist.</p>
</blockquote>
<p>Ich dachte, dafür gibt's <code>std::basic_istream&lt;char, std::char_traits&lt;char&gt;&gt;::sync()</code> .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927233</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927233</guid><dc:creator><![CDATA[Ad aCTa]]></dc:creator><pubDate>Fri, 16 Jul 2010 12:53:14 GMT</pubDate></item><item><title><![CDATA[Reply to Eingabepuffer leeren on Fri, 16 Jul 2010 13:08:11 GMT]]></title><description><![CDATA[<p>Das kann man über den Stream Buffer machen.</p>
<pre><code class="language-cpp">streambuf * pbuf;
pbuf = cin.rdbuf();

int size = pbuf-&gt;in_avail();
cin.ignor(size);
</code></pre>
<p>Lichtlein</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927244</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927244</guid><dc:creator><![CDATA[Lichtlein]]></dc:creator><pubDate>Fri, 16 Jul 2010 13:08:11 GMT</pubDate></item><item><title><![CDATA[Reply to Eingabepuffer leeren on Fri, 16 Jul 2010 13:56:40 GMT]]></title><description><![CDATA[<p>Mit</p>
<pre><code class="language-cpp">while(cin.get() =! '\n');
</code></pre>
<p>wird cin geleert, jedoch muss man wieder die Eingabetaste drücken.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927265</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927265</guid><dc:creator><![CDATA[ccc]]></dc:creator><pubDate>Fri, 16 Jul 2010 13:56:40 GMT</pubDate></item><item><title><![CDATA[Reply to Eingabepuffer leeren on Fri, 16 Jul 2010 13:58:22 GMT]]></title><description><![CDATA[<p>Ich verweise gern noch mal auf sync(). Alle anderen Lösungen sind Quatsch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927269</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927269</guid><dc:creator><![CDATA[Ad aCTa]]></dc:creator><pubDate>Fri, 16 Jul 2010 13:58:22 GMT</pubDate></item><item><title><![CDATA[Reply to Eingabepuffer leeren on Fri, 16 Jul 2010 14:04:51 GMT]]></title><description><![CDATA[<p>Lichtlein schrieb:</p>
<blockquote>
<pre><code class="language-cpp">streambuf * pbuf;
pbuf = cin.rdbuf();

int size = pbuf-&gt;in_avail();
cin.ignor(size);
</code></pre>
</blockquote>
<p>Es verändert den Programmablauf leider irgendwie in keiner Weise.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927272</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927272</guid><dc:creator><![CDATA[ccc]]></dc:creator><pubDate>Fri, 16 Jul 2010 14:04:51 GMT</pubDate></item><item><title><![CDATA[Reply to Eingabepuffer leeren on Fri, 16 Jul 2010 14:07:00 GMT]]></title><description><![CDATA[<p>Ad aCTa schrieb:</p>
<blockquote>
<p>Ich verweise gern noch mal auf sync(). Alle anderen Lösungen sind Quatsch.</p>
</blockquote>
<p>Mit <code>sync()</code> funktioniert es aber auch nicht!<br />
--&gt;Test am Code</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927274</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927274</guid><dc:creator><![CDATA[ccc]]></dc:creator><pubDate>Fri, 16 Jul 2010 14:07:00 GMT</pubDate></item><item><title><![CDATA[Reply to Eingabepuffer leeren on Fri, 16 Jul 2010 14:15:25 GMT]]></title><description><![CDATA[<p>Ad aCTa schrieb:</p>
<blockquote>
<blockquote>
<p>&gt; Wie schon gesagt, liegt dass daran, dass das einfach nicht vorgesehen ist.</p>
</blockquote>
<p>Ich dachte, dafür gibt's <code>std::basic_istream&lt;char, std::char_traits&lt;char&gt;&gt;::sync()</code> .</p>
</blockquote>
<p>Sicher? Also zumindest bei mir funktioniert das damit nicht. Und die Beschreibung im Standard was sync() machen soll ist ziemlich unverständlich, jedoch würde ich es nicht so interpretieren, dass das geforderte Verhalten folgt.</p>
<p>Lichtlein schrieb:</p>
<blockquote>
<p>Das kann man über den Stream Buffer machen.</p>
<pre><code class="language-cpp">streambuf * pbuf;
pbuf = cin.rdbuf();

int size = pbuf-&gt;in_avail();
cin.ignor(size);
</code></pre>
<p>Lichtlein</p>
</blockquote>
<p>Leider liefert in_avail() nur die Mindestzahl der lieferbaren Zeichen. Bei den meisten Streamtypen ist dies immer 0 <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /> . Ansonsten würde es funktionieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927280</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927280</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Fri, 16 Jul 2010 14:15:25 GMT</pubDate></item><item><title><![CDATA[Reply to Eingabepuffer leeren on Fri, 16 Jul 2010 14:34:56 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;

void out_in_avail(std::ostream&amp; os, std::streambuf* buf) {
	os &lt;&lt; buf-&gt;in_avail() &lt;&lt; std::endl;
}

int main() {
	std::string s1;
	std::cin &gt;&gt; s1;
	out_in_avail(std::cout, std::cin.rdbuf());
	std::cin.sync();
	out_in_avail(std::cout, std::cin.rdbuf());
}
</code></pre>
<p>Liefert bei mir:</p>
<pre><code>$ &gt; Hallo
$ &gt; 1                   &lt;--------- Das Newline-Zeichen
$ &gt; 0
</code></pre>
<p>Und genau das soll es auch tun.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927287</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927287</guid><dc:creator><![CDATA[Ad aCTa]]></dc:creator><pubDate>Fri, 16 Jul 2010 14:34:56 GMT</pubDate></item><item><title><![CDATA[Reply to Eingabepuffer leeren on Fri, 16 Jul 2010 14:39:58 GMT]]></title><description><![CDATA[<p>Wenn sync() nicht das tut, was es eigentlich sollte (nämlich alle Zeichen im Eingabepuffer zu verwerfen und den Stream damit zu synchronisieren), kann man es auch mal mit diesem dreckigen Hack probieren:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;

void out_in_avail(std::ostream&amp; os, std::streambuf* buf) {
	os &lt;&lt; buf-&gt;in_avail() &lt;&lt; std::endl;
}

void iflush(std::istream&amp; ios) {
	std::ostream os(ios.rdbuf());
	os.flush();
	ios.rdbuf(os.rdbuf());
}

int main() {
	std::string s1;
	std::cin &gt;&gt; s1;
	out_in_avail(std::cout, std::cin.rdbuf());
	iflush(std::cin);
	out_in_avail(std::cout, std::cin.rdbuf());
	std::cin.get();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1927288</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927288</guid><dc:creator><![CDATA[Ad aCTa]]></dc:creator><pubDate>Fri, 16 Jul 2010 14:39:58 GMT</pubDate></item><item><title><![CDATA[Reply to Eingabepuffer leeren on Fri, 16 Jul 2010 14:54:28 GMT]]></title><description><![CDATA[<p>Nope, liefern bei mir beide</p>
<pre><code>Hallo
0
0
</code></pre>
<p>und es wird am Ende beim get trotzdem nicht gewartet. Getestet unter einem Linux, sowohl mit dem neuesten GCC als auch mit dem neuesten Intel-Compiler.</p>
<p>Und wie ich das sehe, ist dieses Verhalten auch durch den recht lax formulierten Standard gedeckt. Vermutlich gibt es auch gute Gründe dafür warum der Standard so formuliert ist und warum die Compilerhersteller sich nicht die Mühe geben es trotzdem besser zu machen, aber das würde zu ziemlich viel Spekulationen über Dinge führen mit denen ich mich nicht wirklich gut auskenne (Mein Wilder Tipp: Es hat wahrscheinlich was mit dem IO-Modell von POSIX zu tun).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927291</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927291</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Fri, 16 Jul 2010 14:54:28 GMT</pubDate></item><item><title><![CDATA[Reply to Eingabepuffer leeren on Fri, 16 Jul 2010 15:47:23 GMT]]></title><description><![CDATA[<p>Tja, VS 2008 und 2010 machen das so. Aber beim 2. Beispiel sollte es eigentlich überall klappen. Es sei denn, die Definition von ostream::flush() ist auch so lax.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927310</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927310</guid><dc:creator><![CDATA[Ad aCTa]]></dc:creator><pubDate>Fri, 16 Jul 2010 15:47:23 GMT</pubDate></item><item><title><![CDATA[Reply to Eingabepuffer leeren on Sat, 17 Jul 2010 09:50:29 GMT]]></title><description><![CDATA[<p><a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39349.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-39349.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927550</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927550</guid><dc:creator><![CDATA[wxSkip]]></dc:creator><pubDate>Sat, 17 Jul 2010 09:50:29 GMT</pubDate></item><item><title><![CDATA[Reply to Eingabepuffer leeren on Sat, 17 Jul 2010 11:58:40 GMT]]></title><description><![CDATA[<p>Das betrifft den Standard-Eingabestrom des Betriebssystems selbst (stdin) und hat nichts direkt mit den C++-Streams (std::istream) und Puffern zu tun. Als einziges hat man die Semantik des &quot;Istream-Flushens&quot; übernommen: dass es möglichst nicht gehen soll.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927600</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927600</guid><dc:creator><![CDATA[Ad aCTa]]></dc:creator><pubDate>Sat, 17 Jul 2010 11:58:40 GMT</pubDate></item><item><title><![CDATA[Reply to Eingabepuffer leeren on Sat, 17 Jul 2010 13:52:14 GMT]]></title><description><![CDATA[<p><code>std::cin.sync();</code></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927645</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927645</guid><dc:creator><![CDATA[skullyan]]></dc:creator><pubDate>Sat, 17 Jul 2010 13:52:14 GMT</pubDate></item><item><title><![CDATA[Reply to Eingabepuffer leeren on Sat, 17 Jul 2010 14:17:11 GMT]]></title><description><![CDATA[<p>Toll, dass du jetzt auch noch mal sync() erwähnt hast. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1927655</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927655</guid><dc:creator><![CDATA[Ad aCTa]]></dc:creator><pubDate>Sat, 17 Jul 2010 14:17:11 GMT</pubDate></item><item><title><![CDATA[Reply to Eingabepuffer leeren on Sat, 17 Jul 2010 19:23:25 GMT]]></title><description><![CDATA[<p>Meine damalige Lösung in meinem Beleg, die zumindest für mich funktionierte und den Buffer leerte:</p>
<pre><code class="language-cpp">// clear() setzt den Stream zurück
// ignore(std::cin.rdbuf()-&gt;in_avail()) ignoriert alle im eingabepuffer enthaltenen zeichen (Trick von IIRC@www.c-plusplus.net)
// ignore() ignoriert alle restlichen Zeichen (wird unter Linux benötigt)
// Dadurch wird keine Endlosschleife ausgelöst wenn eine leere Eingabe getätigt wurde

#ifdef __unix__
    #define Menue_clearBuffer() std::cin.clear(); std::cin.ignore(std::cin.rdbuf()-&gt;in_avail()); std::cin.ignore();
#else
    #ifdef _MSC_VER
        #define Menue_clearBuffer() std::cin.clear(); std::cin.ignore(std::cin.rdbuf()-&gt;in_avail());
    #else
        #define Menue_clearBuffer() std::cin.clear(); std::cin.ignore(std::cin.rdbuf()-&gt;in_avail()); std::cin.ignore();
    #endif
#endif

// cin/cout Helper funktionen um den Quellcode übersichtlicher zu gestalten
#define Menue_newLine() std::cout &lt;&lt; std::endl;
#define Menue_readLine(label,variable) std::cout &lt;&lt; label &lt;&lt; &quot;: &quot;; std::cin &gt;&gt; variable; Menue_clearBuffer();
#define Menue_printLine(output) std::cout &lt;&lt; output; Menue_newLine();
#define Menue_printTabbedLine(_left, _right, _space) std::cout &lt;&lt; std::setw(_space) &lt;&lt; std::left &lt;&lt; _left &lt;&lt; _right; Menue_newLine();
#define Menue_printSeperator(character) for(int __i = 0; __i &lt; 79; __i++) std::cout &lt;&lt; character; Menue_newLine()
#define Menue_inputWait() Menue_newLine(); Menue_printLine(&quot;Naechste Eingabe erst in 2 Sekunden moeglich.&quot;); Sleep(2000);
#define Menue_addCommandCall(command, function) if(input == command){ function; continue; }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1927815</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1927815</guid><dc:creator><![CDATA[Blackskyliner]]></dc:creator><pubDate>Sat, 17 Jul 2010 19:23:25 GMT</pubDate></item></channel></rss>