<?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[Parsen?]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich möchte einen eingelesenen String in einen int Wert umwandeln.</p>
<p>Gibt's bei c++ auch eine Funktion wie bei Java? Da gibt's ja Integer.parseInt()</p>
<p>viele Grüße</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/275728/parsen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 26 Aug 2026 16:16:53 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/275728.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 20 Oct 2010 05:49:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Parsen? on Wed, 20 Oct 2010 05:49:24 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich möchte einen eingelesenen String in einen int Wert umwandeln.</p>
<p>Gibt's bei c++ auch eine Funktion wie bei Java? Da gibt's ja Integer.parseInt()</p>
<p>viele Grüße</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1967810</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1967810</guid><dc:creator><![CDATA[Manni25]]></dc:creator><pubDate>Wed, 20 Oct 2010 05:49:24 GMT</pubDate></item><item><title><![CDATA[Reply to Parsen? on Wed, 20 Oct 2010 06:08:16 GMT]]></title><description><![CDATA[<p>atoi oder diverse stringstreams</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1967816</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1967816</guid><dc:creator><![CDATA[atoi]]></dc:creator><pubDate>Wed, 20 Oct 2010 06:08:16 GMT</pubDate></item><item><title><![CDATA[Reply to Parsen? on Wed, 20 Oct 2010 06:55:30 GMT]]></title><description><![CDATA[<p>Hier noch der FAQ Eintrag dazu:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39488.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-39488.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1967836</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1967836</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Wed, 20 Oct 2010 06:55:30 GMT</pubDate></item><item><title><![CDATA[Reply to Parsen? on Wed, 20 Oct 2010 08:46:52 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>danke für die Antwort.</p>
<p>Ich hab das mit atoi versucht.</p>
<p>Klappt auch wunderbar, nur wenn ich z.b.: &quot;rrr&quot; eingebe, erscheint null.</p>
<p>Bei Java hätte ich im try Block versucht den String zu parsen und im catch Block dann eine NumberFormatException gecatcht.</p>
<p>Wie funktioniert das in c++?</p>
<p>Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1967885</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1967885</guid><dc:creator><![CDATA[Manni25]]></dc:creator><pubDate>Wed, 20 Oct 2010 08:46:52 GMT</pubDate></item><item><title><![CDATA[Reply to Parsen? on Wed, 20 Oct 2010 09:07:44 GMT]]></title><description><![CDATA[<p>Manni25 schrieb:</p>
<blockquote>
<p>...<br />
Wie funktioniert das in c++?</p>
<p>Danke.</p>
</blockquote>
<p>Im &quot;von C geerbten Subteil&quot; von C++, zu dem atoi() gehört, hast du &quot;Pech gehabt&quot; - die sagen einfach &quot;undefined Behavior&quot;.<br />
Deshalb bliebe dir nicht viel anderes übrig, als vorher per &quot;isdigit()&quot; jedes einzelne Zeichen abzuprüfen.....</p>
<p>... und weil das nicht schön, ist, hat man bei C++ die stringstreams erfunden. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /><br />
Wie das geht, steht im o.g. Thread beschrieben ... und anschließend kannst du den Streamstatus direkt abfragen:</p>
<pre><code class="language-cpp">...
   if(!Str) throw meine_Exception(&quot;Die Konvertierung hat nicht geklappt&quot;);
...
</code></pre>
<p>(geht auch direkt beim Aufruf des operator&gt;&gt;())</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1967888</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1967888</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Wed, 20 Oct 2010 09:07:44 GMT</pubDate></item><item><title><![CDATA[Reply to Parsen? on Wed, 20 Oct 2010 09:20:06 GMT]]></title><description><![CDATA[<p>Optional kannst du dir von den Stringstreams auch eine Exception werfen lassen, falls dir das lieber ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1967894</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1967894</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 20 Oct 2010 09:20:06 GMT</pubDate></item><item><title><![CDATA[Reply to Parsen? on Wed, 20 Oct 2010 09:21:16 GMT]]></title><description><![CDATA[<p>Simon2 schrieb:</p>
<blockquote>
<p>&quot;undefined Behavior&quot;.</p>
</blockquote>
<p>Ist das so?<br />
Im Falle eines (int) Overflows ist das _Ergebnis_ undefiniert. Bei unpassender Eingabe (&quot;rrr&quot;) ist das Ergebnis aber 0.</p>
<blockquote>
<p>The return value is 0 (for atoi and _atoi64), 0L (for atol), or 0.0 (for atof) if the input cannot be converted to a value of that type.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1967896</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1967896</guid><dc:creator><![CDATA[Vicious Falcon]]></dc:creator><pubDate>Wed, 20 Oct 2010 09:21:16 GMT</pubDate></item><item><title><![CDATA[Reply to Parsen? on Wed, 20 Oct 2010 09:36:29 GMT]]></title><description><![CDATA[<p>Simon2 schrieb:</p>
<blockquote>
<p>Im &quot;von C geerbten Subteil&quot; von C++, zu dem atoi() gehört, hast du &quot;Pech gehabt&quot; - die sagen einfach &quot;undefined Behavior&quot;.<br />
Deshalb bliebe dir nicht viel anderes übrig, als vorher per &quot;isdigit()&quot; jedes einzelne Zeichen abzuprüfen.....</p>
</blockquote>
<p>Tja aber nur, wenn man den &quot;von C geerbten Subteil&quot; nur oberflächlich und dessen schon seit C89 für diese Fälle bereitstehenden Funktionen wie strtol inkl. Fehler/Überlaufhandling nicht kennt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1967905</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1967905</guid><dc:creator><![CDATA[Wutz]]></dc:creator><pubDate>Wed, 20 Oct 2010 09:36:29 GMT</pubDate></item><item><title><![CDATA[Reply to Parsen? on Wed, 20 Oct 2010 16:38:10 GMT]]></title><description><![CDATA[<p>Vicious Falcon schrieb:</p>
<blockquote>
<p>Simon2 schrieb:</p>
<blockquote>
<p>&quot;undefined Behavior&quot;.</p>
</blockquote>
<p>Ist das so?<br />
Im Falle eines (int) Overflows ist das _Ergebnis_ undefiniert. Bei unpassender Eingabe (&quot;rrr&quot;) ist das Ergebnis aber 0....</p>
</blockquote>
<p>Hatte vorhin kurz im C99 nachgeschaut (OK - nicht im C++98 und auch nicht ewig rumgesucht) und den Passus so verstanden.</p>
<p>Wutz schrieb:</p>
<blockquote>
<p>...Tja aber nur, wenn man den &quot;von C geerbten Subteil&quot; nur oberflächlich und dessen schon seit C89 für diese Fälle bereitstehenden Funktionen wie strtol inkl. Fehler/Überlaufhandling nicht kennt.</p>
</blockquote>
<p>Ok - habe ich ungeschickt ausgedrückt. Mir ist schon klar, dass man auch in C sicher und sauber Text in Zahlen parsen kann (mache ich auch ständig) - nur eben mit atoi() ein wenig umständlich.<br />
Auch bin ich mir nicht sicher, dass er den Unterschied zwischen &quot;von C geerbtem C++&quot; und &quot;exklusivem C++&quot; kennt - da hielt ich eine Hinweis darauf für angebracht.</p>
<p>Gegenfrage: <em>Wenn</em> der Kollege</p>
<ul>
<li>von Java kommt,</li>
<li>im C++-Forum nachfragt,</li>
<li>den FAQ-Artikel in den Fingern und</li>
<li>mit der Anwendung atoi() und anscheinend</li>
<li>dem Lesen deren Spezifikation dem Probleme hat,</li>
</ul>
<p>... ist dann der Rat zu stringstreams wirklich so verwerflich?</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1968106</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1968106</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Wed, 20 Oct 2010 16:38:10 GMT</pubDate></item><item><title><![CDATA[Reply to Parsen? on Wed, 20 Oct 2010 16:58:25 GMT]]></title><description><![CDATA[<blockquote>
<p>.. ist dann der Rat zu stringstreams wirklich so verwerflich?</p>
</blockquote>
<p>Jedenfalls wurde er gleich verworfen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1968112</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1968112</guid><dc:creator><![CDATA[Panke]]></dc:creator><pubDate>Wed, 20 Oct 2010 16:58:25 GMT</pubDate></item><item><title><![CDATA[Reply to Parsen? on Wed, 20 Oct 2010 17:15:13 GMT]]></title><description><![CDATA[<blockquote>
<p>... ist dann der Rat zu stringstreams wirklich so verwerflich?</p>
</blockquote>
<p>Es ist der einzig richtige Rat.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1968128</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1968128</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Wed, 20 Oct 2010 17:15:13 GMT</pubDate></item><item><title><![CDATA[Reply to Parsen? on Wed, 20 Oct 2010 18:50:24 GMT]]></title><description><![CDATA[<p>boost::lexical_cast</p>
<p>wirft eine bad_cast Exception, falls was schief lief.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1968173</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1968173</guid><dc:creator><![CDATA[asdfasdfasdfasdfASDFASasd]]></dc:creator><pubDate>Wed, 20 Oct 2010 18:50:24 GMT</pubDate></item><item><title><![CDATA[Reply to Parsen? on Wed, 20 Oct 2010 19:46:07 GMT]]></title><description><![CDATA[<p>Java ähnlicher ist Qt, da wäre das ganze ein</p>
<pre><code class="language-cpp">int a = QString(&quot;123&quot;).toInt();
</code></pre>
<p>was mir persönlich lieber ist als die stringstream Variante (für die ich unter MFC auch einen toInt(str) wrapper geschrieben hatte)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1968209</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1968209</guid><dc:creator><![CDATA[pospiech]]></dc:creator><pubDate>Wed, 20 Oct 2010 19:46:07 GMT</pubDate></item><item><title><![CDATA[Reply to Parsen? on Thu, 21 Oct 2010 05:23:51 GMT]]></title><description><![CDATA[<p>Panke schrieb:</p>
<blockquote>
<blockquote>
<p>.. ist dann der Rat zu stringstreams wirklich so verwerflich?</p>
</blockquote>
<p>Jedenfalls wurde er gleich verworfen.</p>
</blockquote>
<p>Vermutlich weil er spontan eine <em>Funktion</em> sucht (deren Konzept er schon kennt) als ein neues <em>Konzept</em>.<br />
Kann ich verstehen, sollte aber trotzdem nicht seine Strategie bleiben....</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1968303</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1968303</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Thu, 21 Oct 2010 05:23:51 GMT</pubDate></item></channel></rss>