<?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[c++0x enum class to string]]></title><description><![CDATA[<p>hallo!</p>
<p>ich hab jetzt ein wenig gegoogelt, aber einen 'standardweg', um aus einer &quot;enum class&quot; einen zugehörigen string zu mappen hab ich nicht gefunden.</p>
<p>dh:</p>
<pre><code>enum class Letters {
 A, B, C
};
</code></pre>
<p>Da wäre es natürlich cool f. div. debug-outputs jederzeit auf einen string mappen zu können.<br />
Eine Möglichkeit wäre natürlich eine neue Klasse zu erstellen, die zB eine</p>
<pre><code>static const char *toSring()
</code></pre>
<p>Methode anbietet...</p>
<p>Welche Wege verwendet ihr?</p>
<p>Danke im Voraus</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/322063/c-0x-enum-class-to-string</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Jul 2026 11:28:29 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/322063.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 05 Dec 2013 12:36:57 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to c++0x enum class to string on Thu, 05 Dec 2013 12:36:57 GMT]]></title><description><![CDATA[<p>hallo!</p>
<p>ich hab jetzt ein wenig gegoogelt, aber einen 'standardweg', um aus einer &quot;enum class&quot; einen zugehörigen string zu mappen hab ich nicht gefunden.</p>
<p>dh:</p>
<pre><code>enum class Letters {
 A, B, C
};
</code></pre>
<p>Da wäre es natürlich cool f. div. debug-outputs jederzeit auf einen string mappen zu können.<br />
Eine Möglichkeit wäre natürlich eine neue Klasse zu erstellen, die zB eine</p>
<pre><code>static const char *toSring()
</code></pre>
<p>Methode anbietet...</p>
<p>Welche Wege verwendet ihr?</p>
<p>Danke im Voraus</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369952</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369952</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Thu, 05 Dec 2013 12:36:57 GMT</pubDate></item><item><title><![CDATA[Reply to c++0x enum class to string on Thu, 05 Dec 2013 12:49:32 GMT]]></title><description><![CDATA[<p>swalkner schrieb:</p>
<blockquote>
<p>Welche Wege verwendet ihr?</p>
</blockquote>
<p>kein Enum verwenden. Hab schon sehr lange nicht mehr gebraucht.</p>
<p>Wenn es wirklich unerlässlich ist, bietet sich</p>
<pre><code class="language-cpp">enum class Letters {
 A, B, C, LAST_LETTER
};
std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, Letters l)
{
  const char* letters_string[static_cast&lt;int&gt;(LAST_LETTER)] = {
    &quot;A&quot;,
    &quot;B&quot;,
    &quot;C&quot;
  };
  assert(static_cast&lt;int&gt;(l) &gt;= 0 &amp;&amp; static_cast&lt;int&gt;(l) &lt; static_cast&lt;int&gt;(LAST_LETTER));
  return os &lt;&lt; letters_string[static_cast&lt;int&gt;(l)];
}
</code></pre>
<p>an.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369954</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369954</guid><dc:creator><![CDATA[toddenemus]]></dc:creator><pubDate>Thu, 05 Dec 2013 12:49:32 GMT</pubDate></item><item><title><![CDATA[Reply to c++0x enum class to string on Thu, 05 Dec 2013 12:51:48 GMT]]></title><description><![CDATA[<p>Ok deine Version hat halt den Nachteil, dass man wirklich von 0 bis n-1 Werte verwenden muss. Das hat man evtl. auch nicht immer.</p>
<p>Warum KEINE Enums? Wie würdest du zB eine State-Machine implementieren? Welche Alternative verwendest du? Bzw. brauchst du die für die Sachen die du implementierst überhaupt...?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369955</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369955</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Thu, 05 Dec 2013 12:51:48 GMT</pubDate></item><item><title><![CDATA[Reply to c++0x enum class to string on Thu, 05 Dec 2013 13:01:05 GMT]]></title><description><![CDATA[<blockquote>
<p>f. div. debug-outputs</p>
</blockquote>
<p>Dann kannst du auch gleich Strings verwenden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369956</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369956</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Thu, 05 Dec 2013 13:01:05 GMT</pubDate></item><item><title><![CDATA[Reply to c++0x enum class to string on Thu, 05 Dec 2013 13:09:39 GMT]]></title><description><![CDATA[<p>State-Machine: <a href="http://www.boost.org/doc/libs/1_55_0/libs/statechart/doc/tutorial.html" rel="nofollow">http://www.boost.org/doc/libs/1_55_0/libs/statechart/doc/tutorial.html</a><br />
Siehst du da irgendwo enums? (Btw: Enums sind manchmal ok, aber switch und if-Kaskaden sollten immer* vermieden werden.)</p>
<p>* In wenigen Fällen kann es für die Performance notwendig sein, aber sehr oft sind Funktionszeiger schneller als switchs.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369958</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369958</guid><dc:creator><![CDATA[toddenemus]]></dc:creator><pubDate>Thu, 05 Dec 2013 13:09:39 GMT</pubDate></item></channel></rss>