<?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[atoi Fehlerprüfung]]></title><description><![CDATA[<p>Hi!</p>
<p>Gibt es eine Möglichkeit, den Rückgabewert o.ä. von <a href="http://msdn.microsoft.com/en-us/library/yd5xkb5c.aspx" rel="nofollow">atoi</a> auf Fehler zu prüfen?</p>
<p>Ich meine keine Fehler wie NULL-Zeiger oder Ganzzahlüberläufe, sondern &quot;Formatfehler&quot;. Es wird nämlich 0 zurückgegeben, wenn die Zeichenkette nicht umgewandelt werden konnte, allerdings ist 0 auch eine gültige Zahl.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/274715/atoi-fehlerprüfung</link><generator>RSS for Node</generator><lastBuildDate>Thu, 27 Aug 2026 08:45:38 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/274715.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 01 Oct 2010 10:24:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to atoi Fehlerprüfung on Fri, 01 Oct 2010 10:24:34 GMT]]></title><description><![CDATA[<p>Hi!</p>
<p>Gibt es eine Möglichkeit, den Rückgabewert o.ä. von <a href="http://msdn.microsoft.com/en-us/library/yd5xkb5c.aspx" rel="nofollow">atoi</a> auf Fehler zu prüfen?</p>
<p>Ich meine keine Fehler wie NULL-Zeiger oder Ganzzahlüberläufe, sondern &quot;Formatfehler&quot;. Es wird nämlich 0 zurückgegeben, wenn die Zeichenkette nicht umgewandelt werden konnte, allerdings ist 0 auch eine gültige Zahl.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1960001</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1960001</guid><dc:creator><![CDATA[De-Be]]></dc:creator><pubDate>Fri, 01 Oct 2010 10:24:34 GMT</pubDate></item><item><title><![CDATA[Reply to atoi Fehlerprüfung on Fri, 01 Oct 2010 10:29:16 GMT]]></title><description><![CDATA[<p>Du kannst dafür <em>errno</em> abfragen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1960002</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1960002</guid><dc:creator><![CDATA[David_pb]]></dc:creator><pubDate>Fri, 01 Oct 2010 10:29:16 GMT</pubDate></item><item><title><![CDATA[Reply to atoi Fehlerprüfung on Fri, 01 Oct 2010 10:31:40 GMT]]></title><description><![CDATA[<p>David_pb schrieb:</p>
<blockquote>
<p>Du kannst dafür <em>errno</em> abfragen.</p>
</blockquote>
<p>Dachte ich auch, aber 1. steht in der Doku nichts davon, und zweitens ist errno &quot;immer&quot; 0.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1960003</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1960003</guid><dc:creator><![CDATA[De-Be]]></dc:creator><pubDate>Fri, 01 Oct 2010 10:31:40 GMT</pubDate></item><item><title><![CDATA[Reply to atoi Fehlerprüfung on Fri, 01 Oct 2010 10:43:26 GMT]]></title><description><![CDATA[<p>Du könntest auch eine C++-Methode zur Umwandlung benutzen. Ein stringstream beispielsweise bietet auch Feedback im Fehlerfall.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1960008</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1960008</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Fri, 01 Oct 2010 10:43:26 GMT</pubDate></item><item><title><![CDATA[Reply to atoi Fehlerprüfung on Fri, 01 Oct 2010 10:48:26 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Du könntest auch eine C++-Methode zur Umwandlung benutzen. Ein stringstream beispielsweise bietet auch Feedback im Fehlerfall.</p>
</blockquote>
<p>Da ist was dran, allerdings ist es nur eine kleine Umwandlung wo ich nicht unbedingt ein Objekt konstruieren wollte.</p>
<p>Btw: Wäre das fail-Bit denn dann gesetzt oder wie müsste ich prüfen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1960010</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1960010</guid><dc:creator><![CDATA[De-Be]]></dc:creator><pubDate>Fri, 01 Oct 2010 10:48:26 GMT</pubDate></item><item><title><![CDATA[Reply to atoi Fehlerprüfung on Fri, 01 Oct 2010 11:10:19 GMT]]></title><description><![CDATA[<p>De-Be schrieb:</p>
<blockquote>
<p>Da ist was dran, allerdings ist es nur eine kleine Umwandlung wo ich nicht unbedingt ein Objekt konstruieren wollte.</p>
</blockquote>
<p>Und? Wenn es nicht superzeitkritisch ist, dann ist ein stringstream doch ok.</p>
<blockquote>
<p>Btw: Wäre das fail-Bit denn dann gesetzt oder wie müsste ich prüfen?</p>
</blockquote>
<p>Jupp. Oder einfach <code>if (stream_objekt &gt;&gt; int_variable) /* ok*/ else /*nicht ok*/</code> . Oder es gibt auch noch die Möglichkeit den Stream so einzustellen, dass er bei Nicht-Gelingen eine Exception wirft.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1960015</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1960015</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Fri, 01 Oct 2010 11:10:19 GMT</pubDate></item><item><title><![CDATA[Reply to atoi Fehlerprüfung on Fri, 01 Oct 2010 12:08:54 GMT]]></title><description><![CDATA[<p>Du kannst dir ja selber was &quot;zusammenhacken&quot;</p>
<pre><code class="language-cpp">int GetDigit(char d, int base)
{
	switch(d)
	{
	case '0':return 0;
	case '1':return 1;
	case '2':return (base&gt;2)?2:-1;
	case '3':return (base&gt;3)?3:-1;
	case '4':return (base&gt;4)?4:-1;
	case '5':return (base&gt;5)?5:-1;
	case '6':return (base&gt;6)?6:-1;
	case '7':return (base&gt;7)?7:-1;
	case '8':return (base&gt;8)?8:-1;
	case '9':return (base&gt;9)?9:-1;
	case 'A':
	case 'a':
		return (base&gt;10)?10:-1;
	case 'B':
	case 'b':
		return (base&gt;11)?11:-1;
	case 'C':
	case 'c':
		return (base&gt;12)?12:-1;
	case 'D':
	case 'd':
		return (base&gt;13)?13:-1;
	case 'E':
	case 'e':
		return (base&gt;14)?14:-1;
	case 'F':
	case 'f':
		return (base&gt;15)?15:-1;
	}
	return -1;
}

template&lt;typename Type&gt;
bool StringToInt(const std::string&amp; s, Type* t, int base=10)
{
	Type k=1;
	int i;
	if(s.length()==0)
		return false;
	*t=0;
	for (i=(s.length()-1);i&gt;=0;i--)
	{
		int d=GetDigit(s[i],base);
		if(d==-1)
		{
			if((s[i]=='-' &amp;&amp; i==0)				// okay- Vorzeichen
				|| (base==16 &amp;&amp; s[i]=='x'))		// oder 'x', wenn base 16 ist
			{
				if(s[i]=='-')
					(*t)*=(-1);
				return true;
			}
			*t=0;
			return false;
		}
		*t+= d*k;
		k*=base;
	}
	return true;
}
</code></pre>
<p>Bei einem Aufruf kannst du immer den Returnwert testen. Von solch einem Code kann ich selber aber nur abraten, ich habe das vor JAHREN einmal geschrieben, voll getestet ist es nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1960046</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1960046</guid><dc:creator><![CDATA[VF]]></dc:creator><pubDate>Fri, 01 Oct 2010 12:08:54 GMT</pubDate></item><item><title><![CDATA[Reply to atoi Fehlerprüfung on Fri, 01 Oct 2010 13:15:56 GMT]]></title><description><![CDATA[<p>Die C++-Lösung ist wohl am besten. Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1960093</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1960093</guid><dc:creator><![CDATA[De-Be]]></dc:creator><pubDate>Fri, 01 Oct 2010 13:15:56 GMT</pubDate></item></channel></rss>