<?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[Menüführung]]></title><description><![CDATA[<p>Hallo</p>
<p>ich will ein kleines Konsolenmenü bauen und habe das unter C immer z.B.: so gelöst</p>
<ol>
<li>irgendwas</li>
<li>was anderes</li>
</ol>
<p>Geben Sie 1 oder 2 ein.</p>
<p>Jetzt würde ich in c++ die eingabe in einen String speichern mit getline, daraus einen stringstream machen und daraus die Zahl auslesen.<br />
Diese dann switchen usw.</p>
<p>Frage.. Passt das so , oder macht ihr Profis das generell anders??</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/328714/menüführung</link><generator>RSS for Node</generator><lastBuildDate>Tue, 07 Jul 2026 07:47:26 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/328714.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 23 Oct 2014 16:43:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Menüführung on Thu, 23 Oct 2014 16:43:28 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>ich will ein kleines Konsolenmenü bauen und habe das unter C immer z.B.: so gelöst</p>
<ol>
<li>irgendwas</li>
<li>was anderes</li>
</ol>
<p>Geben Sie 1 oder 2 ein.</p>
<p>Jetzt würde ich in c++ die eingabe in einen String speichern mit getline, daraus einen stringstream machen und daraus die Zahl auslesen.<br />
Diese dann switchen usw.</p>
<p>Frage.. Passt das so , oder macht ihr Profis das generell anders??</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2423640</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2423640</guid><dc:creator><![CDATA[menu]]></dc:creator><pubDate>Thu, 23 Oct 2014 16:43:28 GMT</pubDate></item><item><title><![CDATA[Reply to Menüführung on Thu, 23 Oct 2014 16:52:53 GMT]]></title><description><![CDATA[<p>Wieso in einen String speichern?<br />
Lies doch direkt von deinem input device.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2423647</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2423647</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Thu, 23 Oct 2014 16:52:53 GMT</pubDate></item><item><title><![CDATA[Reply to Menüführung on Thu, 23 Oct 2014 17:09:36 GMT]]></title><description><![CDATA[<p>Naja, ich dachte hald wenn einer statt &quot;1&quot; z.B. &quot;du kannst mich mal &quot; oder so eingibt. Untersuchen muss ich die Eingabe ja so oder so... ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2423656</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2423656</guid><dc:creator><![CDATA[menu]]></dc:creator><pubDate>Thu, 23 Oct 2014 17:09:36 GMT</pubDate></item><item><title><![CDATA[Reply to Menüführung on Thu, 23 Oct 2014 17:17:07 GMT]]></title><description><![CDATA[<p>Unter Windows? Dann sieh mal hierein, vielleicht kannst Du das gebrauchen:<br />
<a href="http://www.c-plusplus.net/forum/303169" rel="nofollow">http://www.c-plusplus.net/forum/303169</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2423658</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2423658</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Thu, 23 Oct 2014 17:17:07 GMT</pubDate></item><item><title><![CDATA[Reply to Menüführung on Thu, 23 Oct 2014 18:07:55 GMT]]></title><description><![CDATA[<p>Spitzensache! Danke Belli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2423664</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2423664</guid><dc:creator><![CDATA[menu]]></dc:creator><pubDate>Thu, 23 Oct 2014 18:07:55 GMT</pubDate></item><item><title><![CDATA[Reply to Menüführung on Thu, 23 Oct 2014 19:01:49 GMT]]></title><description><![CDATA[<p>menu schrieb:</p>
<blockquote>
<p>Naja, ich dachte hald wenn einer statt &quot;1&quot; z.B. &quot;du kannst mich mal &quot; oder so eingibt. Untersuchen muss ich die Eingabe ja so oder so... ?</p>
</blockquote>
<p>Auch wenn du das evtl. nicht mehr brauchst.<br />
Was denkst du, ist der Unterschied zwischen:</p>
<pre><code>std::cin &gt;&gt; number;
</code></pre>
<p>und</p>
<pre><code>stringstream &gt;&gt; number;
</code></pre>
<p>In beiden Fällen wird bei ungültiger Zahl (&quot;du kannst mich mal&quot;), der Stream auf einen Fehlerzustand gelöscht. Das heißt du brauchst eine Schleife:</p>
<pre><code>while (!std::cin &gt;&gt; number) // solange einlesen nicht klappt, ggf. hier noch Rangecheck einfügen
{
  std::cin.clear(); // resette Fehlerflags
  std::cin.ignore(std::numeric_limits&lt;std::streamsize&gt;::max(), '\n'); // lösche alle Zeichen, die noch im Stream stehen
 // notwendig, weil bei einer Eingabe von 123abc,
 // die Zeichen abc noch im Stream stehen würden,
 // d.h. eine erneute Iteration wieder fehlschlägt
}
</code></pre>
<p>Und du musst dasselbe machen, unabhängig ob du jetzt von einem String ausgehst oder direkt von cin. Den Ansatz &quot;lese String + verarbeite String&quot; haben viele, macht aber keinen Sinn, schließlich können alle Streams direkt verarbeiten. Lese direkt das Format was du brauchst!<br />
Das jetzt nur als Tipp für die Zukunft.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2423676</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2423676</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Thu, 23 Oct 2014 19:01:49 GMT</pubDate></item><item><title><![CDATA[Reply to Menüführung on Thu, 23 Oct 2014 19:06:10 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/29873">@Nathan</a> auch Dir vielen Dank, werde mir das für die Zukunft merken!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2423679</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2423679</guid><dc:creator><![CDATA[menu]]></dc:creator><pubDate>Thu, 23 Oct 2014 19:06:10 GMT</pubDate></item><item><title><![CDATA[Reply to Menüführung on Thu, 23 Oct 2014 21:06:44 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/29873">@Nathan</a>:<br />
In Deinem obigen Beispiel ... würde die Eingabe von 123abc überhaupt einen Fehler im Stream erzeugen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2423710</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2423710</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Thu, 23 Oct 2014 21:06:44 GMT</pubDate></item></channel></rss>