<?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[Größe eines &amp;quot;short&amp;quot; Arrays]]></title><description><![CDATA[<p>Hallo!</p>
<p>Ich erstelle ein Array (oder sagt man in diesem Fall Vector?) aus shorts.</p>
<p>Das sieht so aus:</p>
<p>int i=256;<br />
shorts=new short[i];</p>
<p>Wie könnte ich denn (vorausgesetzt, ich wüsste nicht, dass shorts 255 Elemente hat), die Länge/Größe des Arrays/Vektors abfragen?</p>
<p>int iSize=shorts.size();</p>
<p>geht ja leider nicht, weil es keine Klasse ist.</p>
<p>Und sizeof(shorts) gibt man nur die Länge einer &quot;short&quot;-Variablen zurück, aber ich möchte gerne die Anzahl der Elemente (255) wissen.</p>
<p>Vielen Dank für die Hilfe!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/301335/größe-eines-quot-short-quot-arrays</link><generator>RSS for Node</generator><lastBuildDate>Wed, 12 Aug 2026 06:37:48 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/301335.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 24 Mar 2012 18:24:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Größe eines &amp;quot;short&amp;quot; Arrays on Sat, 24 Mar 2012 18:24:31 GMT]]></title><description><![CDATA[<p>Hallo!</p>
<p>Ich erstelle ein Array (oder sagt man in diesem Fall Vector?) aus shorts.</p>
<p>Das sieht so aus:</p>
<p>int i=256;<br />
shorts=new short[i];</p>
<p>Wie könnte ich denn (vorausgesetzt, ich wüsste nicht, dass shorts 255 Elemente hat), die Länge/Größe des Arrays/Vektors abfragen?</p>
<p>int iSize=shorts.size();</p>
<p>geht ja leider nicht, weil es keine Klasse ist.</p>
<p>Und sizeof(shorts) gibt man nur die Länge einer &quot;short&quot;-Variablen zurück, aber ich möchte gerne die Anzahl der Elemente (255) wissen.</p>
<p>Vielen Dank für die Hilfe!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2195013</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2195013</guid><dc:creator><![CDATA[tmighty]]></dc:creator><pubDate>Sat, 24 Mar 2012 18:24:31 GMT</pubDate></item><item><title><![CDATA[Reply to Größe eines &amp;quot;short&amp;quot; Arrays on Sat, 24 Mar 2012 18:27:43 GMT]]></title><description><![CDATA[<p>Die Anzahl der Elemente steht doch in i. <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2195014</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2195014</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Sat, 24 Mar 2012 18:27:43 GMT</pubDate></item><item><title><![CDATA[Reply to Größe eines &amp;quot;short&amp;quot; Arrays on Sat, 24 Mar 2012 18:29:48 GMT]]></title><description><![CDATA[<p>kannst du nicht, weil du nur nen zeiger auf den anfang des arrays hast.</p>
<p>aber wieso nimmst du kein std::vector&lt;short&gt;? dann könntest du ganz bequem die größe heraus finden und musst dich nicht um die freigabe des arrays kümmern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2195015</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2195015</guid><dc:creator><![CDATA[vario-500]]></dc:creator><pubDate>Sat, 24 Mar 2012 18:29:48 GMT</pubDate></item><item><title><![CDATA[Reply to Größe eines &amp;quot;short&amp;quot; Arrays on Sat, 24 Mar 2012 18:31:46 GMT]]></title><description><![CDATA[<p>Ich denke das geht nicht, wenn du nur einen Zeiger auf das Array hast. Woher willst du mit einem Zeiger wissen, wie gross der Array-Block ist.</p>
<p>Was geht ist folgendes (ist aber natuerlich nicht das selbe):</p>
<pre><code class="language-cpp">short data[256];
	cout &lt;&lt; sizeof(data) / sizeof(short) &lt;&lt; endl;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2195016</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2195016</guid><dc:creator><![CDATA[icarus2]]></dc:creator><pubDate>Sat, 24 Mar 2012 18:31:46 GMT</pubDate></item><item><title><![CDATA[Reply to Größe eines &amp;quot;short&amp;quot; Arrays on Sat, 24 Mar 2012 18:40:22 GMT]]></title><description><![CDATA[<p>vario-500 schrieb:</p>
<blockquote>
<p>aber wieso nimmst du kein std::vector&lt;short&gt;? dann könntest du ganz bequem die größe heraus finden und musst dich nicht um die freigabe des arrays kümmern.</p>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /><br />
Verstehe ich auch nicht. std::vector ist, was du möchtest. new braucht man in C++ im allgemeinen recht selten. (Mit make_unique gar nicht. ;))</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2195021</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2195021</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Sat, 24 Mar 2012 18:40:22 GMT</pubDate></item><item><title><![CDATA[Reply to Größe eines &amp;quot;short&amp;quot; Arrays on Sat, 24 Mar 2012 19:15:00 GMT]]></title><description><![CDATA[<p>icarus2 schrieb:</p>
<blockquote>
<p>Ich denke das geht nicht, wenn du nur einen Zeiger auf das Array hast. Woher willst du mit einem Zeiger wissen, wie gross der Array-Block ist.</p>
<p>Was geht ist folgendes (ist aber natuerlich nicht das selbe):</p>
<pre><code class="language-cpp">short data[256];
	cout &lt;&lt; sizeof(data) / sizeof(short) &lt;&lt; endl;
</code></pre>
</blockquote>
<p>Blöd. Besser:</p>
<pre><code class="language-cpp">short data[256];
	cout &lt;&lt; sizeof (data) / sizeof (*data) &lt;&lt; '\n';
</code></pre>
<p>Funktioniert nur bei &quot;echten&quot; Arrays.</p>
<p>Edit³: egal.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2195030</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2195030</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Sat, 24 Mar 2012 19:15:00 GMT</pubDate></item><item><title><![CDATA[Reply to Größe eines &amp;quot;short&amp;quot; Arrays on Sun, 25 Mar 2012 11:59:28 GMT]]></title><description><![CDATA[<p>Hacker schrieb:</p>
<blockquote>
<p>Blöd. Besser:</p>
<pre><code class="language-cpp">short data[256];
	cout &lt;&lt; sizeof (data) / sizeof (*data) &lt;&lt; '\n';
</code></pre>
<p>Funktioniert nur bei &quot;echten&quot; Arrays.</p>
</blockquote>
<p>Auch blöd. Noch besser:</p>
<pre><code class="language-cpp">std::array&lt;short, 256&gt; data;
  std::cout &lt;&lt; data.size() &lt;&lt; '\n';
</code></pre>
<p>Einfach drauf verzichten, mit rohen C-Arrays rumzupfuschen <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/2195186</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2195186</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Sun, 25 Mar 2012 11:59:28 GMT</pubDate></item><item><title><![CDATA[Reply to Größe eines &amp;quot;short&amp;quot; Arrays on Sun, 25 Mar 2012 13:52:55 GMT]]></title><description><![CDATA[<p>pumuckl schrieb:</p>
<blockquote>
<p>Hacker schrieb:</p>
<blockquote>
<p>Blöd. Besser:</p>
<pre><code class="language-cpp">short data[256];
	cout &lt;&lt; sizeof (data) / sizeof (*data) &lt;&lt; '\n';
</code></pre>
<p>Funktioniert nur bei &quot;echten&quot; Arrays.</p>
</blockquote>
<p>Auch blöd. Noch besser:</p>
<pre><code class="language-cpp">std::array&lt;short, 256&gt; data;
  std::cout &lt;&lt; data.size() &lt;&lt; '\n';
</code></pre>
<p>Einfach drauf verzichten, mit rohen C-Arrays rumzupfuschen <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>Nein! Du verstehst nicht. Ich meinte jetzt nur wegen der Methode für Rohe Arrays. Das man die überhaupt nicht benutzen soll, ist doch klar <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="😃"
    /></p>
<p>Edit: Die Frage des TEs war aber nicht, was besser ist, pumuckl, also war deine Antwort eigentlich &quot;Auch blöd&quot;.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2195209</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2195209</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Sun, 25 Mar 2012 13:52:55 GMT</pubDate></item></channel></rss>