<?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[cin.sync(); cin.clear; funktioniert nicht!]]></title><description><![CDATA[<p>Hallo zusammen,<br />
ich lerne gerade mit einem Buch C++. Am Ende des Kapitels 'Funktionen' sind nun übungsaufgaben. Ich soll eine inline-Funktion Max schreiben, die das Maximum von x und y zurückgibt und dann noch Max überladen durch eine weitere inline-Funktion für Argumente vom Typ char.</p>
<p>Wenn ich beim Testen der ersten inline-Funktion statt einer Gleitpunktzahl ein Buchstabe eingebe dann kommt eine entsprechende Meldung und eigentlich solle es dann ungestört weitergehen. Das funktioniert aber nicht.</p>
<pre><code>./209_2
Geben Sie bitte zwei Zahlen ein.
4
g
Fehlerhafte Eingabe!

Geben Sie bitte zwei Buchstaben ein.
b
x = g ist das Maximum
</code></pre>
<p>Hier ist der Code: was habe ich falsch gemacht?</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

inline double Max(double x, double y)
{
	return ((x &lt; y) ? y : x);
}

inline char Max(char x, char y)
{
	return ((x &lt; y) ? y : x);
}

int main()
{
	double x, y;
	char xc, yc;
	cout &lt;&lt; &quot;Geben Sie bitte zwei Zahlen ein.&quot; &lt;&lt; endl;
	if( cin &gt;&gt; x &amp;&amp; cin &gt;&gt; y)
	{
	cout &lt;&lt; (x == Max(x, y) ? &quot;x = &quot; : &quot;y = &quot;) &lt;&lt; Max(x, y) &lt;&lt; &quot; ist das Maximum&quot; &lt;&lt; endl;
	}
	else
	{
	cout &lt;&lt; &quot;Fehlerhafte Eingabe!&quot; &lt;&lt; endl;
	}

	cin.sync(); cin.clear();			// Falls eine falsche Eingabe gemacht wurde.

	cout &lt;&lt; &quot;\n\nGeben Sie bitte zwei Buchstaben ein.&quot; &lt;&lt; endl;
	if(cin &gt;&gt; xc &amp;&amp; cin &gt;&gt; yc)
	{	cout &lt;&lt; (xc == Max(xc, yc) ? &quot;x = &quot; : &quot;y = &quot;) &lt;&lt; Max(xc, yc) &lt;&lt; &quot; ist das Maximum&quot; &lt;&lt; endl;}
	else
	{	cout &lt;&lt; &quot;Fehlerhafte Eingabe!&quot; &lt;&lt; endl;}

	return 0;
}
</code></pre>
<p>Vielen Dank.<br />
powerflo</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/191963/cin-sync-cin-clear-funktioniert-nicht</link><generator>RSS for Node</generator><lastBuildDate>Sun, 27 Sep 2026 06:51:34 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/191963.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 08 Sep 2007 19:37:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to cin.sync(); cin.clear; funktioniert nicht! on Sat, 08 Sep 2007 19:52:12 GMT]]></title><description><![CDATA[<p>Hallo zusammen,<br />
ich lerne gerade mit einem Buch C++. Am Ende des Kapitels 'Funktionen' sind nun übungsaufgaben. Ich soll eine inline-Funktion Max schreiben, die das Maximum von x und y zurückgibt und dann noch Max überladen durch eine weitere inline-Funktion für Argumente vom Typ char.</p>
<p>Wenn ich beim Testen der ersten inline-Funktion statt einer Gleitpunktzahl ein Buchstabe eingebe dann kommt eine entsprechende Meldung und eigentlich solle es dann ungestört weitergehen. Das funktioniert aber nicht.</p>
<pre><code>./209_2
Geben Sie bitte zwei Zahlen ein.
4
g
Fehlerhafte Eingabe!

Geben Sie bitte zwei Buchstaben ein.
b
x = g ist das Maximum
</code></pre>
<p>Hier ist der Code: was habe ich falsch gemacht?</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

inline double Max(double x, double y)
{
	return ((x &lt; y) ? y : x);
}

inline char Max(char x, char y)
{
	return ((x &lt; y) ? y : x);
}

int main()
{
	double x, y;
	char xc, yc;
	cout &lt;&lt; &quot;Geben Sie bitte zwei Zahlen ein.&quot; &lt;&lt; endl;
	if( cin &gt;&gt; x &amp;&amp; cin &gt;&gt; y)
	{
	cout &lt;&lt; (x == Max(x, y) ? &quot;x = &quot; : &quot;y = &quot;) &lt;&lt; Max(x, y) &lt;&lt; &quot; ist das Maximum&quot; &lt;&lt; endl;
	}
	else
	{
	cout &lt;&lt; &quot;Fehlerhafte Eingabe!&quot; &lt;&lt; endl;
	}

	cin.sync(); cin.clear();			// Falls eine falsche Eingabe gemacht wurde.

	cout &lt;&lt; &quot;\n\nGeben Sie bitte zwei Buchstaben ein.&quot; &lt;&lt; endl;
	if(cin &gt;&gt; xc &amp;&amp; cin &gt;&gt; yc)
	{	cout &lt;&lt; (xc == Max(xc, yc) ? &quot;x = &quot; : &quot;y = &quot;) &lt;&lt; Max(xc, yc) &lt;&lt; &quot; ist das Maximum&quot; &lt;&lt; endl;}
	else
	{	cout &lt;&lt; &quot;Fehlerhafte Eingabe!&quot; &lt;&lt; endl;}

	return 0;
}
</code></pre>
<p>Vielen Dank.<br />
powerflo</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1361547</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1361547</guid><dc:creator><![CDATA[powerflo]]></dc:creator><pubDate>Sat, 08 Sep 2007 19:52:12 GMT</pubDate></item><item><title><![CDATA[Reply to cin.sync(); cin.clear; funktioniert nicht! on Sun, 09 Sep 2007 09:45:42 GMT]]></title><description><![CDATA[<pre><code>cin.sync(); cin.clear(); // Falls eine falsche Eingabe gemacht wurde
cin.ignore(numeric_limits&lt;streamsize&gt;::max(), '\n'); // Puffer löschen
</code></pre>
<p>Außerdem, die char Funktion wird hier implizit gecastet falls du zum Beispiel ein int eingibst. Da int auf char und char auf int abzubilden ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1361745</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1361745</guid><dc:creator><![CDATA[DeleteBuffer]]></dc:creator><pubDate>Sun, 09 Sep 2007 09:45:42 GMT</pubDate></item><item><title><![CDATA[Reply to cin.sync(); cin.clear; funktioniert nicht! on Sun, 09 Sep 2007 09:47:40 GMT]]></title><description><![CDATA[<p>Ach und ....<br />
#include &lt;limits&gt;</p>
<p>habe ich vergessen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1361746</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1361746</guid><dc:creator><![CDATA[DeleteBuffer]]></dc:creator><pubDate>Sun, 09 Sep 2007 09:47:40 GMT</pubDate></item><item><title><![CDATA[Reply to cin.sync(); cin.clear; funktioniert nicht! on Sun, 09 Sep 2007 12:10:10 GMT]]></title><description><![CDATA[<p>Vielen Dank. Jetzt klappt es <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>
<p>DeleteBuffer schrieb:</p>
<blockquote>
<p>Außerdem, die char Funktion wird hier implizit gecastet falls du zum Beispiel ein int eingibst. Da int auf char und char auf int abzubilden ist.</p>
</blockquote>
<p>Bin wie gesagt ein Anfänger. Muss ich das verstehen?</p>
<p>DeleteBuffer schrieb:</p>
<blockquote>
<p>Ach und ....<br />
#include &lt;limits&gt;</p>
<p>habe ich vergessen.</p>
</blockquote>
<p>Wieso? Es hat auch ohne funktioniert...</p>
<p>Gruß<br />
powerflo</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1361850</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1361850</guid><dc:creator><![CDATA[powerflo]]></dc:creator><pubDate>Sun, 09 Sep 2007 12:10:10 GMT</pubDate></item></channel></rss>