<?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[Überprüfung von Variablen auf Gültigkeit]]></title><description><![CDATA[<p>Hallo,<br />
ich möchte in meinem Programm alle Input-Werte auf Gültig prüfen.<br />
So muss ich zum Beispiel überprüfen ob char im bereich 0 bis 255 liegt.<br />
Wie lässt sich das am effektivsten überprüfen?<br />
Mit</p>
<pre><code class="language-cpp">if((char &gt;= 0) &amp;&amp; (char &lt;= 255))
{ do...}
</code></pre>
<p>Oder gibt es hierfür eine bessere Methode?</p>
<p>Wie muss ich dann float überprüfen? Welche Wertebereiche hat float?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/181125/überprüfung-von-variablen-auf-gültigkeit</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Apr 2026 01:17:26 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/181125.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 10 May 2007 08:13:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Überprüfung von Variablen auf Gültigkeit on Thu, 10 May 2007 08:13:42 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich möchte in meinem Programm alle Input-Werte auf Gültig prüfen.<br />
So muss ich zum Beispiel überprüfen ob char im bereich 0 bis 255 liegt.<br />
Wie lässt sich das am effektivsten überprüfen?<br />
Mit</p>
<pre><code class="language-cpp">if((char &gt;= 0) &amp;&amp; (char &lt;= 255))
{ do...}
</code></pre>
<p>Oder gibt es hierfür eine bessere Methode?</p>
<p>Wie muss ich dann float überprüfen? Welche Wertebereiche hat float?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1282153</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1282153</guid><dc:creator><![CDATA[maRKus23]]></dc:creator><pubDate>Thu, 10 May 2007 08:13:42 GMT</pubDate></item><item><title><![CDATA[Reply to Überprüfung von Variablen auf Gültigkeit on Thu, 10 May 2007 08:20:59 GMT]]></title><description><![CDATA[<p>Ein (unsigned) char liegt normalerweise im Bereich 0..255 (außer du hast ein Exoten-System, bei dem ein Byte mehr als 8 Bit hat - oder bei deinem System sind char's vorzeichenbehaftet). Also was genau willst du da eigentlich überprüfen?</p>
<p>Wenn du feststellen willst, ob eine String-Eingabe als float/int/whatever erkannt werden kann, wandel sie einfach um und fang mögliche Umwandlungsfehler ab, z.B:</p>
<pre><code class="language-cpp">char* test = ...;
char* ende;
double val = strtod(test,&amp;ende);
if(*ende !='\0')
  cout&lt;&lt;&quot;Fehler&quot;;

//oder

string test = ...;
ostringstream str(test);
double val; str&gt;&gt;val;
if(!str)
  cout&lt;&lt;&quot;Fehler&quot;;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1282161</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1282161</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 10 May 2007 08:20:59 GMT</pubDate></item><item><title><![CDATA[Reply to Überprüfung von Variablen auf Gültigkeit on Thu, 10 May 2007 09:42:54 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">string test = ...;
ostringstream str(test);
double val; str&gt;&gt;val;
if(!str)
  cout&lt;&lt;&quot;Fehler&quot;;
</code></pre>
<p>Die variable test ist der String den ich im Editfeld eingegeben habe?<br />
Was macht ostringstream str(test);?<br />
Was macht str&gt;&gt;val;?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1282229</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1282229</guid><dc:creator><![CDATA[maRKus23]]></dc:creator><pubDate>Thu, 10 May 2007 09:42:54 GMT</pubDate></item><item><title><![CDATA[Reply to Überprüfung von Variablen auf Gültigkeit on Thu, 10 May 2007 09:47:11 GMT]]></title><description><![CDATA[<p>maRKus23 schrieb:</p>
<blockquote>
<p>Die variable test ist der String den ich im Editfeld eingegeben habe?</p>
</blockquote>
<p>Ja</p>
<blockquote>
<p>Was macht ostringstream str(test);?</p>
</blockquote>
<p>Initialisiert einen Stringstream mit dem Inhalt deines Eingabestrings.</p>
<blockquote>
<p>Was macht str&gt;&gt;val;?</p>
</blockquote>
<p>Liest aus dem Stream in die double-Variable 'val'.</p>
<p>(für ausführlichere Erkärungen empfehle ich einen Blick in die C++ FAQ - &quot;Einmal String nach Zahl und zurück&quot;)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1282230</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1282230</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 10 May 2007 09:47:11 GMT</pubDate></item><item><title><![CDATA[Reply to Überprüfung von Variablen auf Gültigkeit on Thu, 10 May 2007 10:12:29 GMT]]></title><description><![CDATA[<p>Ahja danke!!!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1282253</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1282253</guid><dc:creator><![CDATA[maRKus23]]></dc:creator><pubDate>Thu, 10 May 2007 10:12:29 GMT</pubDate></item></channel></rss>