<?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[Abfrage der Größe eines Vektors]]></title><description><![CDATA[<p>Hallo alle zusammen!</p>
<p>Ich bin gerade dabei einen Elektrorechner zu programmieren, jetzt möchte ich, dass das Programm abfragt, wie viele Widerstände die zu berechnende Schaltung hat, also wie groß der Vektor ist.</p>
<p>Bis jetzt habe ich durch probieren nur herausgefunden, wie man alle Werte ausgibt:</p>
<p>while (a &lt; elem.size()) {<br />
cout &lt;&lt; elem [a] &lt;&lt; '\n';<br />
a ++; }</p>
<p>Hat jemand eine Ahnung wie das funktioniert? Gibt es dafür eine bestimmte Funktion?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/298063/abfrage-der-größe-eines-vektors</link><generator>RSS for Node</generator><lastBuildDate>Fri, 14 Aug 2026 04:58:52 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/298063.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 12 Jan 2012 17:32:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Abfrage der Größe eines Vektors on Thu, 12 Jan 2012 17:32:35 GMT]]></title><description><![CDATA[<p>Hallo alle zusammen!</p>
<p>Ich bin gerade dabei einen Elektrorechner zu programmieren, jetzt möchte ich, dass das Programm abfragt, wie viele Widerstände die zu berechnende Schaltung hat, also wie groß der Vektor ist.</p>
<p>Bis jetzt habe ich durch probieren nur herausgefunden, wie man alle Werte ausgibt:</p>
<p>while (a &lt; elem.size()) {<br />
cout &lt;&lt; elem [a] &lt;&lt; '\n';<br />
a ++; }</p>
<p>Hat jemand eine Ahnung wie das funktioniert? Gibt es dafür eine bestimmte Funktion?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2167284</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2167284</guid><dc:creator><![CDATA[chickn]]></dc:creator><pubDate>Thu, 12 Jan 2012 17:32:35 GMT</pubDate></item><item><title><![CDATA[Reply to Abfrage der Größe eines Vektors on Thu, 12 Jan 2012 17:42:39 GMT]]></title><description><![CDATA[<p>Hä?</p>
<p>elem.size() <strong>ist</strong> die Größe des Vektors</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2167292</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2167292</guid><dc:creator><![CDATA[ghjghj]]></dc:creator><pubDate>Thu, 12 Jan 2012 17:42:39 GMT</pubDate></item><item><title><![CDATA[Reply to Abfrage der Größe eines Vektors on Thu, 12 Jan 2012 17:43:01 GMT]]></title><description><![CDATA[<p>chickn schrieb:</p>
<blockquote>
<pre><code class="language-cpp">elem.size()
</code></pre>
</blockquote>
<p>Die Antwort steht doch schon in deinem Code <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="😕"
    /><br />
Kleine Bettlektüre: <a href="http://www.cplusplus.com/reference/stl/vector-Referenz/" rel="nofollow">vector</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2167294</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2167294</guid><dc:creator><![CDATA[hmmh]]></dc:creator><pubDate>Thu, 12 Jan 2012 17:43:01 GMT</pubDate></item><item><title><![CDATA[Reply to Abfrage der Größe eines Vektors on Thu, 12 Jan 2012 17:44:53 GMT]]></title><description><![CDATA[<p>Guck mal hier:<br />
<a href="http://cplusplus.com/reference/stl/vector/" rel="nofollow">http://cplusplus.com/reference/stl/vector/</a></p>
<p>Ich würde den Vector mit Iteratoren durchlaufen <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="😉"
    /><br />
Die Anzahl der Elemente kriegt man mit size() raus. Das hast du doch schon! - Ansonsten würde die Schleife doch nicht funktionieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2167295</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2167295</guid><dc:creator><![CDATA[F4B1]]></dc:creator><pubDate>Thu, 12 Jan 2012 17:44:53 GMT</pubDate></item><item><title><![CDATA[Reply to Abfrage der Größe eines Vektors on Thu, 12 Jan 2012 17:49:53 GMT]]></title><description><![CDATA[<p>Also das ist mein ganzer code:</p>
<pre><code>{   
    int a;
    vector&lt;int&gt; elem (5);                 //Definition des arrays (Datentyp &quot;int&quot;, Name elem, 5 Elemente) 
    cout &lt;&lt; &quot;Der Vektor hat &quot; &lt;&lt; elem.size() &lt;&lt; &quot; Elemente.&quot; &lt;&lt; '\n';       //Anzahl der Elemente anzeigen                                              
    elem [2]=22;                                //Der eingegebene Wert 22 wird als Element 2 gespeichert           
    cout &lt;&lt; elem [0] &lt;&lt;'\n';                    //Wert ausgeben (Inhalt des Elementes 0)
    cout &lt;&lt; elem [2] &lt;&lt;'\n';                    //Wert ausgeben (Inhalt des Elementes 2) 
    cout &lt;&lt; &quot;Gib den Wert fuer das 3. Element ein: &quot;;
    cin &gt;&gt; elem [4];                            //Wert eingeben für Element 3      
        a = 0; 
        while (a &lt; elem.size())                 {
              cout &lt;&lt; elem [a] &lt;&lt; '\n';
              a ++;                              }   
        cin&gt;&gt;elem.size();
    system(&quot;PAUSE&quot;);
    return EXIT_SUCCESS;
}
</code></pre>
<p>die vektorgröße ist<br />
vector&lt;int&gt; elem (5);</p>
<p>ich möchte aber die vektorgröße selber bestimmen, während das programm läuft.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2167299</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2167299</guid><dc:creator><![CDATA[chickn]]></dc:creator><pubDate>Thu, 12 Jan 2012 17:49:53 GMT</pubDate></item><item><title><![CDATA[Reply to Abfrage der Größe eines Vektors on Thu, 12 Jan 2012 17:51:31 GMT]]></title><description><![CDATA[<p>Du willst also die Größe verändern - dann guck dir mal resize() an:</p>
<p><a href="http://cplusplus.com/reference/stl/vector/resize/" rel="nofollow">http://cplusplus.com/reference/stl/vector/resize/</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2167302</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2167302</guid><dc:creator><![CDATA[F4B1]]></dc:creator><pubDate>Thu, 12 Jan 2012 17:51:31 GMT</pubDate></item><item><title><![CDATA[Reply to Abfrage der Größe eines Vektors on Thu, 12 Jan 2012 17:56:17 GMT]]></title><description><![CDATA[<p>Ich möchte die Größe nicht verändern. Das Programm soll mich Fragen, wie viele Widerstände meine Schaltung hat. Dann gebe ich eine Zahl ein. Diese Zahl soll dann die Größe des Vektores sein, also die Anzahl der Widerstände.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2167306</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2167306</guid><dc:creator><![CDATA[chickn]]></dc:creator><pubDate>Thu, 12 Jan 2012 17:56:17 GMT</pubDate></item><item><title><![CDATA[Reply to Abfrage der Größe eines Vektors on Thu, 12 Jan 2012 18:00:56 GMT]]></title><description><![CDATA[<p>chickn schrieb:</p>
<blockquote>
<p>Ich möchte die Größe nicht verändern. Das Programm soll mich Fragen, wie viele Widerstände meine Schaltung hat. Dann gebe ich eine Zahl ein. Diese Zahl soll dann die Größe des Vektores sein, also die Anzahl der Widerstände.</p>
</blockquote>
<p>Dann gibst du bei der Erstellung des vectors direkt diese Zahl an. Gute Regel: Variablen immer erst dann erstellen, wenn sie tatsächlich gebraucht werden. Normalerweise steht dann auch schon der Anfangszustand vollständig fest und man kann gleich alles richtig initialisieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2167310</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2167310</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 12 Jan 2012 18:00:56 GMT</pubDate></item><item><title><![CDATA[Reply to Abfrage der Größe eines Vektors on Thu, 12 Jan 2012 18:14:19 GMT]]></title><description><![CDATA[<p>So etwas in der Art meinte ich (es funktioniert nicht):</p>
<pre><code>#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;vector&gt;

using namespace std;

int main(int argc, char *argv[])
{
    int a;
    vector&lt;int&gt; widerstand(a);
    cout&lt;&lt;&quot;Gebe die Anzahl der Widerstaende ein: &quot;;
    cin&gt;&gt;a;
    cout&lt;&lt;&quot;\n\nDie Schaltung hat &quot;&lt;&lt;widerstand.size()&lt;&lt;&quot; Widerstände.&quot;;
    system(&quot;PAUSE&quot;);
    return EXIT_SUCCESS;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2167315</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2167315</guid><dc:creator><![CDATA[chickn]]></dc:creator><pubDate>Thu, 12 Jan 2012 18:14:19 GMT</pubDate></item><item><title><![CDATA[Reply to Abfrage der Größe eines Vektors on Thu, 12 Jan 2012 18:20:36 GMT]]></title><description><![CDATA[<p>chickn schrieb:</p>
<blockquote>
<p>So etwas in der Art meinte ich (es funktioniert nicht):</p>
<pre><code class="language-cpp">#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;vector&gt;

using namespace std;

int main(int argc, char *argv[])
{
    int a;
    vector&lt;int&gt; widerstand(a);  // hier wird die Grösse des vectors auf den aktuellen Wert von a gesetzt (irgendwo zw. 0..random)
    cout&lt;&lt;&quot;Gebe die Anzahl der Widerstaende ein: &quot;;
    cin&gt;&gt;a;                     // die Wertänderung von a hat keinen Einfluss auf den vector
    cout&lt;&lt;&quot;\n\nDie Schaltung hat &quot;&lt;&lt;widerstand.size()&lt;&lt;&quot; Widerstände.&quot;;
    system(&quot;PAUSE&quot;);
    return EXIT_SUCCESS;
}
</code></pre>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/2167320</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2167320</guid><dc:creator><![CDATA[__cu]]></dc:creator><pubDate>Thu, 12 Jan 2012 18:20:36 GMT</pubDate></item><item><title><![CDATA[Reply to Abfrage der Größe eines Vektors on Thu, 12 Jan 2012 18:24:59 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">int main() {
  std::size_t a;
  std::cin &gt;&gt; a;
  std::vector&lt;int&gt; widerstand(a);
  std::cout &lt;&lt; widerstand.size() &lt;&lt; std::endl;
  // ...
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2167323</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2167323</guid><dc:creator><![CDATA[rüdiger]]></dc:creator><pubDate>Thu, 12 Jan 2012 18:24:59 GMT</pubDate></item><item><title><![CDATA[Reply to Abfrage der Größe eines Vektors on Thu, 12 Jan 2012 18:24:55 GMT]]></title><description><![CDATA[<p>Ahhhh ich muss a also vorher bestimmen. Vielen Dank <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/2167324</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2167324</guid><dc:creator><![CDATA[chickn]]></dc:creator><pubDate>Thu, 12 Jan 2012 18:24:55 GMT</pubDate></item><item><title><![CDATA[Reply to Abfrage der Größe eines Vektors on Thu, 12 Jan 2012 18:26:12 GMT]]></title><description><![CDATA[<p>Oder resize benutzen oder einfach so oft push_back/insert wie du brauchst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2167325</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2167325</guid><dc:creator><![CDATA[rüdiger]]></dc:creator><pubDate>Thu, 12 Jan 2012 18:26:12 GMT</pubDate></item></channel></rss>