<?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[Fehlerüberprüfung bei cout?]]></title><description><![CDATA[<p>Hi,</p>
<p>für die Schule schreibe ich gerade ein Programm unter Linux.<br />
Unser Lehrer will, dass wir alle Rückgabewerte - auch printf - überprüfen.<br />
Nun verwende ich aber nicht printf, sondern iostream.<br />
Wie kann ich überprüfen, ob bei einem Code wie</p>
<pre><code class="language-cpp">cout &lt;&lt; &quot;Ein String&quot;;
</code></pre>
<p>ein Fehler aufgetreten ist?</p>
<p>Geht das mit .fail()?<br />
Ich kann es leider nicht ausprobieren, da mir keine Situation einfällt wo die Ausgabe auf der Konsole fehlschlagen könnte.</p>
<p>Kann ich mit cout.fail() alle Fehlerfälle abfangen, genauso wie man mit printf()&lt;0 ?</p>
<p>mfg. Tubos</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/140028/fehlerüberprüfung-bei-cout</link><generator>RSS for Node</generator><lastBuildDate>Mon, 31 Aug 2026 00:19:10 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/140028.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 11 Mar 2006 13:16:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Fehlerüberprüfung bei cout? on Sat, 11 Mar 2006 13:16:42 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>für die Schule schreibe ich gerade ein Programm unter Linux.<br />
Unser Lehrer will, dass wir alle Rückgabewerte - auch printf - überprüfen.<br />
Nun verwende ich aber nicht printf, sondern iostream.<br />
Wie kann ich überprüfen, ob bei einem Code wie</p>
<pre><code class="language-cpp">cout &lt;&lt; &quot;Ein String&quot;;
</code></pre>
<p>ein Fehler aufgetreten ist?</p>
<p>Geht das mit .fail()?<br />
Ich kann es leider nicht ausprobieren, da mir keine Situation einfällt wo die Ausgabe auf der Konsole fehlschlagen könnte.</p>
<p>Kann ich mit cout.fail() alle Fehlerfälle abfangen, genauso wie man mit printf()&lt;0 ?</p>
<p>mfg. Tubos</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1013954</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1013954</guid><dc:creator><![CDATA[Tubos]]></dc:creator><pubDate>Sat, 11 Mar 2006 13:16:42 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlerüberprüfung bei cout? on Sat, 11 Mar 2006 13:37:00 GMT]]></title><description><![CDATA[<p>Exceptions fangen?</p>
<p>Bye, TGGC (<a href="http://tggc.tg.funpic.de/index.php?cat=1&amp;page=8" rel="nofollow">Fakten</a>)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1013969</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1013969</guid><dc:creator><![CDATA[TGGC]]></dc:creator><pubDate>Sat, 11 Mar 2006 13:37:00 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlerüberprüfung bei cout? on Sat, 11 Mar 2006 14:10:25 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<blockquote>
<p>Geht das mit .fail()?</p>
</blockquote>
<p>Ja.</p>
<blockquote>
<p>Ich kann es leider nicht ausprobieren, da mir keine Situation einfällt wo die Ausgabe auf der Konsole fehlschlagen könnte.</p>
</blockquote>
<p>cout ist auch nur ein Stream, er könnte aber genausogut eine zum Schreiben geöffnete Datei sein. Sagen wir mal, du darfst z.B. nicht schreiben, weil du keine Rechte besitzt, dann kannst du das abfragen.</p>
<p>TGGC schrieb:</p>
<blockquote>
<p>Exceptions fangen?</p>
</blockquote>
<p>Auf good() prüfen müsste es auch tun.</p>
<p>MfG</p>
<p>GPC</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1013973</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1013973</guid><dc:creator><![CDATA[GPC]]></dc:creator><pubDate>Sat, 11 Mar 2006 14:10:25 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlerüberprüfung bei cout? on Sat, 11 Mar 2006 14:18:56 GMT]]></title><description><![CDATA[<p>Ok.</p>
<p>fail() ist aber nicht dasselbe wie !good(), hab ich gelesen.<br />
good überprüft mehr.<br />
Das heißt ich sollte good() verwenden. Richtig?</p>
<p>Exceptions will ich nicht verwenden, sonst tut sich mein Lehrer schwer das Programm zu verstehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1013984</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1013984</guid><dc:creator><![CDATA[Tubos]]></dc:creator><pubDate>Sat, 11 Mar 2006 14:18:56 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlerüberprüfung bei cout? on Sat, 11 Mar 2006 14:20:22 GMT]]></title><description><![CDATA[<blockquote>
<p>fail() ist aber nicht dasselbe wie !good(), hab ich gelesen.</p>
</blockquote>
<p>Stimmt.</p>
<blockquote>
<p>good überprüft mehr.</p>
</blockquote>
<p>good() prüft auf fail(), bad() und eof(). Deckt so ziemlich alles ab <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<blockquote>
<p>Das heißt ich sollte good() verwenden. Richtig?</p>
</blockquote>
<p>Richtig.</p>
<p>MfG</p>
<p>GPC</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1013988</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1013988</guid><dc:creator><![CDATA[GPC]]></dc:creator><pubDate>Sat, 11 Mar 2006 14:20:22 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlerüberprüfung bei cout? on Sat, 11 Mar 2006 14:23:13 GMT]]></title><description><![CDATA[<p>Und wie willst du solch einen Fehler behandeln?^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1013992</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1013992</guid><dc:creator><![CDATA[^^]]></dc:creator><pubDate>Sat, 11 Mar 2006 14:23:13 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlerüberprüfung bei cout? on Sat, 11 Mar 2006 14:36:47 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">if(std::cout &lt;&lt; &quot;Ausgabe&quot; &lt;&lt; std::endl)
    return true;
else
    return false;
</code></pre>
<p>Where's da problem?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1014011</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1014011</guid><dc:creator><![CDATA[ceplusplus]]></dc:creator><pubDate>Sat, 11 Mar 2006 14:36:47 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlerüberprüfung bei cout? on Sat, 11 Mar 2006 14:44:44 GMT]]></title><description><![CDATA[<p>ceplusplus schrieb:</p>
<blockquote>
<pre><code class="language-cpp">if(std::cout &lt;&lt; &quot;Ausgabe&quot; &lt;&lt; std::endl)
    return true;
else
    return false;
</code></pre>
<p>Where's da problem?</p>
</blockquote>
<p>lol.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1014019</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1014019</guid><dc:creator><![CDATA[roflmao]]></dc:creator><pubDate>Sat, 11 Mar 2006 14:44:44 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlerüberprüfung bei cout? on Sat, 11 Mar 2006 14:45:30 GMT]]></title><description><![CDATA[<p>aber man muss dem user des programms doch auch irgendwie den fehler melden^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1014020</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1014020</guid><dc:creator><![CDATA[^^]]></dc:creator><pubDate>Sat, 11 Mar 2006 14:45:30 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlerüberprüfung bei cout? on Sat, 11 Mar 2006 14:49:51 GMT]]></title><description><![CDATA[<p>*nachdenkt*:</p>
<pre><code class="language-cpp">if(std::cout &lt;&lt; &quot;Ausgabe&quot; &lt;&lt; std::endl) 
    if(std::cout &lt;&lt; &quot;Ausgabe ok!&quot; &lt;&lt; std::endl)
        if(std::cout &lt;&lt; &quot;Ausgabe ok ok!&quot; &lt;&lt; std::endl)
</code></pre>
<p>Ihr habt ja recht, das war nicht optimal <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1014025</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1014025</guid><dc:creator><![CDATA[ceplusplus]]></dc:creator><pubDate>Sat, 11 Mar 2006 14:49:51 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlerüberprüfung bei cout? on Sat, 11 Mar 2006 15:36:35 GMT]]></title><description><![CDATA[<p>Haha, darüber hab ich auch schon gerätselt <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 />
Die Lösung ist aber einfach: statt auf stdout auf stderr ausgeben.<br />
Oder in C++: Statt cout cerr.</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/11030">@ceplusplus</a>: Der &lt;&lt; Operator gibt keinen bool, sondern eine Referenz auf den Stream zurück. Der Returnwert hat keine Aussagekraft.<br />
(Wenn ich das Ganze richtig verstanden habe).</p>
<p>Danke für die HIlfe!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1014064</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1014064</guid><dc:creator><![CDATA[Tubos]]></dc:creator><pubDate>Sat, 11 Mar 2006 15:36:35 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlerüberprüfung bei cout? on Sat, 11 Mar 2006 15:42:11 GMT]]></title><description><![CDATA[<blockquote>
<p>Die Lösung ist aber einfach: statt auf stdout auf stderr ausgeben.</p>
</blockquote>
<p>Und wenn das auch fehlschlägt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1014067</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1014067</guid><dc:creator><![CDATA[^^]]></dc:creator><pubDate>Sat, 11 Mar 2006 15:42:11 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlerüberprüfung bei cout? on Sat, 11 Mar 2006 15:43:10 GMT]]></title><description><![CDATA[<p>Dann beende ich einfach das Programm.</p>
<p>So eine gute Fehlerüberprüfung hat aber nichtmal das Programm meines Lehrers <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1014069</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1014069</guid><dc:creator><![CDATA[Tubos]]></dc:creator><pubDate>Sat, 11 Mar 2006 15:43:10 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlerüberprüfung bei cout? on Sat, 11 Mar 2006 17:50:41 GMT]]></title><description><![CDATA[<p>wenn cerr auch fehlschlägt, dann startest du deine kleine kernelhacking routine, die alle an das system angeschlossenen ausgabegeräte abcheckt. und wenn davon keins funktioniert, dann morst du die ausgabe per blinkender scroll-lock led.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1014155</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1014155</guid><dc:creator><![CDATA[fehlerbehandler]]></dc:creator><pubDate>Sat, 11 Mar 2006 17:50:41 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlerüberprüfung bei cout? on Sat, 11 Mar 2006 17:53:25 GMT]]></title><description><![CDATA[<p>fehlerbehandler schrieb:</p>
<blockquote>
<p>wenn cerr auch fehlschlägt, dann startest du deine kleine kernelhacking routine, die alle an das system angeschlossenen ausgabegeräte abcheckt. und wenn davon keins funktioniert, dann morst du die ausgabe per blinkender scroll-lock led.</p>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1014160</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1014160</guid><dc:creator><![CDATA[ceplusplus]]></dc:creator><pubDate>Sat, 11 Mar 2006 17:53:25 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlerüberprüfung bei cout? on Sat, 11 Mar 2006 18:16:16 GMT]]></title><description><![CDATA[<p>fehlerbehandler schrieb:</p>
<blockquote>
<p>wenn cerr auch fehlschlägt, dann startest du deine kleine kernelhacking routine, die alle an das system angeschlossenen ausgabegeräte abcheckt. und wenn davon keins funktioniert, dann morst du die ausgabe per blinkender scroll-lock led.</p>
</blockquote>
<p>nice ^^<br />
post doch mal den quellcode der kernelhacking routine, dann bekommst auch ein keks von mir <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1014180</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1014180</guid><dc:creator><![CDATA[keksmann]]></dc:creator><pubDate>Sat, 11 Mar 2006 18:16:16 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlerüberprüfung bei cout? on Sat, 11 Mar 2006 19:53:38 GMT]]></title><description><![CDATA[<p>Anders als ich zuvor behauptet habe, müsste<br />
if (!(cout &lt;&lt; &quot;test))<br />
funktionieren. Denn mit cin geht es ja auch.</p>
<p>edit:<br />
Ich glaube ich verwende jetzt doch die oben angegebene Syntax. Das sollte laut der C++ FAQ light auch funktionieren:</p>
<blockquote>
<p>The operator void*() cast operator returns some non-NULL pointer if the stream is in a good state, or NULL if it's in a failed state.</p>
</blockquote>
<p>(<a href="http://www.parashift.com/c++-faq-lite/input-output.html" rel="nofollow">http://www.parashift.com/c++-faq-lite/input-output.html</a>).<br />
Oder kann mir jemand einen Grund sagen wieso es nicht funktionieren sollte?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1014236</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1014236</guid><dc:creator><![CDATA[Tubos]]></dc:creator><pubDate>Sat, 11 Mar 2006 19:53:38 GMT</pubDate></item><item><title><![CDATA[Reply to Fehlerüberprüfung bei cout? on Sat, 11 Mar 2006 23:41:09 GMT]]></title><description><![CDATA[<p>keksmann schrieb:</p>
<blockquote>
<p>fehlerbehandler schrieb:</p>
<blockquote>
<p>wenn cerr auch fehlschlägt, dann startest du deine kleine kernelhacking routine, die alle an das system angeschlossenen ausgabegeräte abcheckt. und wenn davon keins funktioniert, dann morst du die ausgabe per blinkender scroll-lock led.</p>
</blockquote>
<p>nice ^^<br />
post doch mal den quellcode der kernelhacking routine, dann bekommst auch ein keks von mir <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>
</blockquote>
<p>klar, das geht so:</p>
<pre><code class="language-cpp">int main(){float *f;f = (float*)malloc(sizeof(double));*f = M_PI;*(++f) = M_PI;--f;void *v;v = f;double *d;d = (double*)v;}
</code></pre>
<p>(sorry, was beknackteres is mir auf die schnelle nich eingefallen ;))</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1014299</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1014299</guid><dc:creator><![CDATA[fehlerbehandler]]></dc:creator><pubDate>Sat, 11 Mar 2006 23:41:09 GMT</pubDate></item></channel></rss>