<?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[Stringanzahl eines Stringarrays]]></title><description><![CDATA[<p>Hallo zusammen!</p>
<p>Ich habe folgendes Problem. Ich habe ein Array aus Strings (std::string keine C-Strings) und möchte die Anzahl dieser in dem Array herausfinden. Für C-Strings wüsste ich eine Lösung, allerdings fällt mir bei std::string's so banal die Lösung wahrscheinlich auch sein wird keine Lösung ein.</p>
<p>Danke im voraus für die Hilfe</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/293158/stringanzahl-eines-stringarrays</link><generator>RSS for Node</generator><lastBuildDate>Sun, 16 Aug 2026 13:09:08 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/293158.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 26 Sep 2011 14:53:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Stringanzahl eines Stringarrays on Mon, 26 Sep 2011 14:53:08 GMT]]></title><description><![CDATA[<p>Hallo zusammen!</p>
<p>Ich habe folgendes Problem. Ich habe ein Array aus Strings (std::string keine C-Strings) und möchte die Anzahl dieser in dem Array herausfinden. Für C-Strings wüsste ich eine Lösung, allerdings fällt mir bei std::string's so banal die Lösung wahrscheinlich auch sein wird keine Lösung ein.</p>
<p>Danke im voraus für die Hilfe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2123914</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2123914</guid><dc:creator><![CDATA[daispro]]></dc:creator><pubDate>Mon, 26 Sep 2011 14:53:08 GMT</pubDate></item><item><title><![CDATA[Reply to Stringanzahl eines Stringarrays on Mon, 26 Sep 2011 14:54:49 GMT]]></title><description><![CDATA[<p>Wenn du nur einen Zeiger auf das Array hast, gar nicht.</p>
<p>Ansonsten:</p>
<pre><code class="language-cpp">template &lt;typename T, int N&gt;
int array_size(T (&amp;a) [N])
{
    return N;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2123918</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2123918</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Mon, 26 Sep 2011 14:54:49 GMT</pubDate></item><item><title><![CDATA[Reply to Stringanzahl eines Stringarrays on Mon, 26 Sep 2011 14:57:53 GMT]]></title><description><![CDATA[<p>Sorry, aber ich habe mit Templates noch nie gearbeitet.</p>
<p>Kannst du mir evtl. eine kleine Erklärung zu dem Codeschnipsel geben?</p>
<p>Danke <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/2123921</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2123921</guid><dc:creator><![CDATA[daispro]]></dc:creator><pubDate>Mon, 26 Sep 2011 14:57:53 GMT</pubDate></item><item><title><![CDATA[Reply to Stringanzahl eines Stringarrays on Mon, 26 Sep 2011 15:04:17 GMT]]></title><description><![CDATA[<p>Naja, es gibt die Größe <code>N</code> eines Arrays <code>T[ N ]</code> zurück ^^</p>
<p>alternativ: <code>sizeof( array ) / sizeof( array[ 0 ] )</code></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2123922</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2123922</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Mon, 26 Sep 2011 15:04:17 GMT</pubDate></item><item><title><![CDATA[Reply to Stringanzahl eines Stringarrays on Mon, 26 Sep 2011 15:05:41 GMT]]></title><description><![CDATA[<p>daispro schrieb:</p>
<blockquote>
<p>Hallo zusammen!</p>
<p>Ich habe folgendes Problem. Ich habe ein Array aus Strings (std::string keine C-Strings) und möchte die Anzahl dieser in dem Array herausfinden. Für C-Strings wüsste ich eine Lösung, allerdings fällt mir bei std::string's so banal die Lösung wahrscheinlich auch sein wird keine Lösung ein.</p>
<p>Danke im voraus für die Hilfe</p>
</blockquote>
<p>Wie legst Du das Array an?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2123924</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2123924</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Mon, 26 Sep 2011 15:05:41 GMT</pubDate></item><item><title><![CDATA[Reply to Stringanzahl eines Stringarrays on Mon, 26 Sep 2011 15:08:01 GMT]]></title><description><![CDATA[<p>Okay, lassen wir mal den Parameter T weg, dann haben wir:</p>
<pre><code class="language-cpp">template &lt;int N&gt;
int array_size(std::string (&amp;a) [N])
{
    return N;
}
</code></pre>
<p>Templates sind ganz einfach Vorlagen für Funktionen. (Gibts natürlich auch für Klassen, aber hier eine Funktion) Wenn du ein Array mit 3 Elementen namens &quot;myarray&quot; hast, kannst du diese Funktion so aufrufen:</p>
<pre><code class="language-cpp">array_size&lt;3&gt;(myarray); // gibt 3 zurück
</code></pre>
<p>Der Compiler weiß aber natürlich, dass das Array 3 Elemente hat und ist so schlau, dass du ihm das nicht mehr hinschreiben musst (Man sagt, er kann den Template-Parameter &quot;deduzieren&quot;.)</p>
<p>Der Compiler sieht also, der Funktionsaufruf würde mit N = 3 funktionieren und erzeugt eine passende Funktion, die schlussendlich so aussieht:</p>
<pre><code class="language-cpp">int array_size(std::string (&amp;a) [3])
{
    return 3;
}
</code></pre>
<p>Allerdings solltest du rohe Arrays in C++ nicht verwenden, es sei denn, du hast einen guten Grund dafür.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2123925</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2123925</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Mon, 26 Sep 2011 15:08:01 GMT</pubDate></item></channel></rss>