<?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[[Gelöst]switch anweisung verkürzen[Neue Frage]]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe in meinem Programm eine switch anweisung und wenn eine Zahl eins,zwei oder drei ist wird eine andere Zahl auch eins,zwei ,drei...</p>
<pre><code class="language-cpp">switch (val) {
case 1:
 val1 = 1;
 break;
case 2: 
 val1 = 2;
 break;
case 3:
 val1 = 3;
 break;
default:
 cout &lt;&lt; &quot;Fehler!&quot;;
 exit(1);
 break;
}
</code></pre>
<p>jetzt war meien Frage ob man dies auch kürzer scheiben kann...</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/279307/gelöst-switch-anweisung-verkürzen-neue-frage</link><generator>RSS for Node</generator><lastBuildDate>Mon, 24 Aug 2026 16:28:52 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/279307.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 23 Dec 2010 12:27:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [Gelöst]switch anweisung verkürzen[Neue Frage] on Thu, 23 Dec 2010 13:30:45 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe in meinem Programm eine switch anweisung und wenn eine Zahl eins,zwei oder drei ist wird eine andere Zahl auch eins,zwei ,drei...</p>
<pre><code class="language-cpp">switch (val) {
case 1:
 val1 = 1;
 break;
case 2: 
 val1 = 2;
 break;
case 3:
 val1 = 3;
 break;
default:
 cout &lt;&lt; &quot;Fehler!&quot;;
 exit(1);
 break;
}
</code></pre>
<p>jetzt war meien Frage ob man dies auch kürzer scheiben kann...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1998256</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1998256</guid><dc:creator><![CDATA[numberone123]]></dc:creator><pubDate>Thu, 23 Dec 2010 13:30:45 GMT</pubDate></item><item><title><![CDATA[Reply to [Gelöst]switch anweisung verkürzen[Neue Frage] on Thu, 23 Dec 2010 12:29:32 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">if (val &gt;= 1 &amp;&amp; val &lt;= 3)
  val1 = val;
else {
  cout &lt;&lt; &quot;Fehler!&quot;;
  exit(1);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1998257</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1998257</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Thu, 23 Dec 2010 12:29:32 GMT</pubDate></item><item><title><![CDATA[Reply to [Gelöst]switch anweisung verkürzen[Neue Frage] on Thu, 23 Dec 2010 12:30:14 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">if(val &lt; 1 || val &gt; 3)
{
  std::cout &lt;&lt; &quot;Fehler&quot;;
  // mach was.
}
else
{
  val1 = val;
}
</code></pre>
<p>Ich würde nicht <code>exit</code> verwenden in C++, da <code>exit</code> keine Destruktoren aufruft. Wirf lieber eine Exception.</p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1998259</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1998259</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Thu, 23 Dec 2010 12:30:14 GMT</pubDate></item><item><title><![CDATA[Reply to [Gelöst]switch anweisung verkürzen[Neue Frage] on Thu, 23 Dec 2010 12:57:24 GMT]]></title><description><![CDATA[<p>ah danke leutz...probiers mal aus....</p>
<p>edit: Funktioniert danke....</p>
<p>hab jetzt och ne frage...also ich benutzte ein Array z.b. val[20] und benutze diese einzehlnt also so val[0],val[1] und habe dies als switch anweisung ...wenn val1 = 0 dann val[0]...und dann val1++<br />
wenn val1 = 1...dann val[1]...</p>
<pre><code class="language-cpp">switch (val1) {
case 0:
val[0] = 'a'
break;
case 1:
val[1] = 'b'
break;
</code></pre>
<p>und wollte dies auch kürzer gestalten...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1998260</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1998260</guid><dc:creator><![CDATA[numberone123]]></dc:creator><pubDate>Thu, 23 Dec 2010 12:57:24 GMT</pubDate></item><item><title><![CDATA[Reply to [Gelöst]switch anweisung verkürzen[Neue Frage] on Thu, 23 Dec 2010 12:55:02 GMT]]></title><description><![CDATA[<p>Der Index kann natürlich auch variabel sein, d.h.:</p>
<pre><code class="language-cpp">val[val1] = 'a' + val1;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1998271</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1998271</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Thu, 23 Dec 2010 12:55:02 GMT</pubDate></item><item><title><![CDATA[Reply to [Gelöst]switch anweisung verkürzen[Neue Frage] on Thu, 23 Dec 2010 12:59:10 GMT]]></title><description><![CDATA[<p>Ich finde eigentlich für solche Auswahl-Zuweisungs-Ausdrücke switch/case echt gut geeignet. Egal ob man es kürzer ausdrücken kann, es ist ziemlich übersichtlich.<br />
In deinem Fall wäre</p>
<pre><code class="language-cpp">val[val1] = &quot;ab&quot;[val1];
</code></pre>
<p>Sehr kurz.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1998274</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1998274</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Thu, 23 Dec 2010 12:59:10 GMT</pubDate></item><item><title><![CDATA[Reply to [Gelöst]switch anweisung verkürzen[Neue Frage] on Thu, 23 Dec 2010 13:22:30 GMT]]></title><description><![CDATA[<p>ah gute idee danke<br />
probiere es gleich mal aus...</p>
<p>edit:<br />
das Problem mit switch case ist das das array [20] und die anweisung ein wenig groß wird <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    />... daher suchte ich eien alternative aber so richig hunbekommen tu ichs net...</p>
<p>naja danke euch allen habs jetzt...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1998277</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1998277</guid><dc:creator><![CDATA[numberone123]]></dc:creator><pubDate>Thu, 23 Dec 2010 13:22:30 GMT</pubDate></item></channel></rss>