<?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[trycatchthrow_Fachwissen]]></title><description><![CDATA[<p>Hallo liebe C++ Freunde, Ich muss mich mit der Funktionsweise von trycatchthrow auseinandersetzen und habe das Prinzip und den Sinn ungefähr verstanden aber es mangelt an Fachkenntnissen: Hier ein Beispiel:</p>
<pre><code>#include&lt;iostream&gt;
#include&lt;stdexcept&gt;
using namespace std;

void eingabesicherheitssequenz();

int main() {
    char entscheidung;
    do { cin.sync();
        try { eingabesicherheitssequenz(); }
        catch (domain_error&amp; exc) {cout&lt;&lt;&quot;Exception caught:&quot; &lt;&lt; exc.what() &lt;&lt; endl;}
    cin.clear();
    cin.sync();
    cout&lt;&lt;&quot;Weitere Zahlen einlesen? (y/n)&quot;;
    cin&gt;&gt;entscheidung;
    }while (cin &amp;&amp; entscheidung =='y');
    return 0;
}    

void eingabesicherheitssequenz(){
    int zahl1{};
    int zahl2{};
    int merkregister{};
    int n{1};

    cout&lt;&lt;&quot;Zwei positive ganze Zahlen eingeben: &quot;;
    cin&gt;&gt;zahl1&gt;&gt;zahl2;
    if (zahl1&lt;=0 || zahl2 &lt;= 0)  {
        cout&lt;&lt;&quot;Fehleingabe, Programmabruch&quot;&lt;&lt;endl;
        throw domain_error(&quot;die Eingabe enthaelt negative Argumente&quot;);
    }

    while(zahl1 != zahl2) {
        cout&lt;&lt;zahl1&lt;&lt;&quot;\t&quot;&lt;&lt;zahl2&lt;&lt;endl;
        if (zahl1&lt;zahl2)  { zahl2 = zahl2-zahl1; }
        else{
            merkregister = zahl1;
            zahl1=zahl2;
            zahl2=merkregister-zahl1;
        }
        ++n;
        cout&lt;&lt;zahl1&lt;&lt;&quot;\t&quot;&lt;&lt;zahl2&lt;&lt;&quot;\n&quot;&lt;&lt;&quot;Schritte  &quot;;
        n &gt; 1 ? cout &lt;&lt; &quot;e&quot; : false;
        cout &lt;&lt; &quot;zum ggT&quot; &lt;&lt; endl;
    }

}
</code></pre>
<p>Wozu sind die Anweisungen in den Zeilen 10 13 und 14 gut ?</p>
<pre><code>cin.clear();
cin.sync();
</code></pre>
<p>muss man für diese Prozedur den Algorithmus immer aus der main in eine Funktion<br />
auslagern oder geht es auch anders ?<br />
Hat jemand gute Beispiele auf Lager ?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/332691/trycatchthrow_fachwissen</link><generator>RSS for Node</generator><lastBuildDate>Mon, 27 Apr 2026 15:12:22 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/332691.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 17 May 2015 11:36:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to trycatchthrow_Fachwissen on Sun, 17 May 2015 12:33:05 GMT]]></title><description><![CDATA[<p>Hallo liebe C++ Freunde, Ich muss mich mit der Funktionsweise von trycatchthrow auseinandersetzen und habe das Prinzip und den Sinn ungefähr verstanden aber es mangelt an Fachkenntnissen: Hier ein Beispiel:</p>
<pre><code>#include&lt;iostream&gt;
#include&lt;stdexcept&gt;
using namespace std;

void eingabesicherheitssequenz();

int main() {
    char entscheidung;
    do { cin.sync();
        try { eingabesicherheitssequenz(); }
        catch (domain_error&amp; exc) {cout&lt;&lt;&quot;Exception caught:&quot; &lt;&lt; exc.what() &lt;&lt; endl;}
    cin.clear();
    cin.sync();
    cout&lt;&lt;&quot;Weitere Zahlen einlesen? (y/n)&quot;;
    cin&gt;&gt;entscheidung;
    }while (cin &amp;&amp; entscheidung =='y');
    return 0;
}    

void eingabesicherheitssequenz(){
    int zahl1{};
    int zahl2{};
    int merkregister{};
    int n{1};

    cout&lt;&lt;&quot;Zwei positive ganze Zahlen eingeben: &quot;;
    cin&gt;&gt;zahl1&gt;&gt;zahl2;
    if (zahl1&lt;=0 || zahl2 &lt;= 0)  {
        cout&lt;&lt;&quot;Fehleingabe, Programmabruch&quot;&lt;&lt;endl;
        throw domain_error(&quot;die Eingabe enthaelt negative Argumente&quot;);
    }

    while(zahl1 != zahl2) {
        cout&lt;&lt;zahl1&lt;&lt;&quot;\t&quot;&lt;&lt;zahl2&lt;&lt;endl;
        if (zahl1&lt;zahl2)  { zahl2 = zahl2-zahl1; }
        else{
            merkregister = zahl1;
            zahl1=zahl2;
            zahl2=merkregister-zahl1;
        }
        ++n;
        cout&lt;&lt;zahl1&lt;&lt;&quot;\t&quot;&lt;&lt;zahl2&lt;&lt;&quot;\n&quot;&lt;&lt;&quot;Schritte  &quot;;
        n &gt; 1 ? cout &lt;&lt; &quot;e&quot; : false;
        cout &lt;&lt; &quot;zum ggT&quot; &lt;&lt; endl;
    }

}
</code></pre>
<p>Wozu sind die Anweisungen in den Zeilen 10 13 und 14 gut ?</p>
<pre><code>cin.clear();
cin.sync();
</code></pre>
<p>muss man für diese Prozedur den Algorithmus immer aus der main in eine Funktion<br />
auslagern oder geht es auch anders ?<br />
Hat jemand gute Beispiele auf Lager ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2453799</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2453799</guid><dc:creator><![CDATA[softpad]]></dc:creator><pubDate>Sun, 17 May 2015 12:33:05 GMT</pubDate></item><item><title><![CDATA[Reply to trycatchthrow_Fachwissen on Sun, 17 May 2015 13:34:45 GMT]]></title><description><![CDATA[<blockquote>
<p>muss man für diese Prozedur den Algorithmus immer aus der main in eine Funktion<br />
auslagern oder geht es auch anders ?</p>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>Mit cin.clear() werden die Fehlerflags gelöscht und cin.sync() synchronisiert den Eingabepuffer. Viel mehr möchte ich auch ehrlich gesagt nicht zu deinem Code sagen, außer eventuell, dass er schrecklich ist :| .</p>
<p>Hier findest du unter &quot;istream&quot; ggf. noch weitere Informationen zu cin.clear() und sync() : <a href="http://www.cplusplus.com/reference/" rel="nofollow">http://www.cplusplus.com/reference/</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2453809</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2453809</guid><dc:creator><![CDATA[NeeLa]]></dc:creator><pubDate>Sun, 17 May 2015 13:34:45 GMT</pubDate></item><item><title><![CDATA[Reply to trycatchthrow_Fachwissen on Sun, 17 May 2015 17:58:46 GMT]]></title><description><![CDATA[<p>NeeLa schrieb:</p>
<blockquote>
<blockquote>
<p>muss man für diese Prozedur den Algorithmus immer aus der main in eine Funktion<br />
auslagern oder geht es auch anders ?</p>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>Mit cin.clear() werden die Fehlerflags gelöscht und cin.sync() synchronisiert den Eingabepuffer.</p>
</blockquote>
<p>Nicht wirklich. Es sync macht tendenziell überhaupt gar nichts. Der Code wird nicht wie gewünscht funktionieren.</p>
<blockquote>
<p>Viel mehr möchte ich auch ehrlich gesagt nicht zu deinem Code sagen, außer eventuell, dass er schrecklich ist :| .</p>
</blockquote>
<p>Das ist alles, was man dazu zu sagen hat. Der Threadersteller hat diesen Code wohl nicht selber geschrieben sondern will diesen als Vorbild nehmen? Schlechte Idee.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2453830</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2453830</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 17 May 2015 17:58:46 GMT</pubDate></item></channel></rss>