<?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++ Primer 3.3.3]]></title><description><![CDATA[<p>Hey, this is my program:</p>
<pre><code>std::vector&lt;int&gt; test(5);
    int a, b, c, d, s;
    std::cin &gt;&gt; a &gt;&gt; b &gt;&gt; c &gt;&gt; d;
    test.push_back(a);
    test.push_back(b);
    test.push_back(c);
    test.push_back(d);
    s = test[0] + test [1];
    std::cout &lt;&lt; s &lt;&lt; std::endl;
    s = test[2] + test [3];
    std::cout &lt;&lt; s &lt;&lt; std::endl;
    s = test[4] + test [5];
    std::cout &lt;&lt; s &lt;&lt; std::endl;
    s = test[0] + test [5];
    std::cout &lt;&lt; s &lt;&lt; std::endl;
</code></pre>
<p>it shall print the sum of the pairs and the sum of the first and last number in 'test'. I did write and read stuff this way already with strings, but now when i use ints, it doesn't work ...</p>
<p>if i input '1 2 3 4' the output is '0 0 1 1'<br />
if i input '1 1 1 1' its the same.</p>
<p>please help me,<br />
thanks.</p>
<p>Benno</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/324059/c-primer-3-3-3</link><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Jul 2026 02:12:51 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/324059.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 01 Mar 2014 12:32:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to C++ Primer 3.3.3 on Sat, 01 Mar 2014 12:32:59 GMT]]></title><description><![CDATA[<p>Hey, this is my program:</p>
<pre><code>std::vector&lt;int&gt; test(5);
    int a, b, c, d, s;
    std::cin &gt;&gt; a &gt;&gt; b &gt;&gt; c &gt;&gt; d;
    test.push_back(a);
    test.push_back(b);
    test.push_back(c);
    test.push_back(d);
    s = test[0] + test [1];
    std::cout &lt;&lt; s &lt;&lt; std::endl;
    s = test[2] + test [3];
    std::cout &lt;&lt; s &lt;&lt; std::endl;
    s = test[4] + test [5];
    std::cout &lt;&lt; s &lt;&lt; std::endl;
    s = test[0] + test [5];
    std::cout &lt;&lt; s &lt;&lt; std::endl;
</code></pre>
<p>it shall print the sum of the pairs and the sum of the first and last number in 'test'. I did write and read stuff this way already with strings, but now when i use ints, it doesn't work ...</p>
<p>if i input '1 2 3 4' the output is '0 0 1 1'<br />
if i input '1 1 1 1' its the same.</p>
<p>please help me,<br />
thanks.</p>
<p>Benno</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2385922</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2385922</guid><dc:creator><![CDATA[hihohohi]]></dc:creator><pubDate>Sat, 01 Mar 2014 12:32:59 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Primer 3.3.3 on Sat, 01 Mar 2014 12:41:20 GMT]]></title><description><![CDATA[<p>hihohohi schrieb:</p>
<blockquote>
<p>Hey, this is my program:</p>
<pre><code>std::vector&lt;int&gt; test(5);
    int a, b, c, d, s;
    std::cin &gt;&gt; a &gt;&gt; b &gt;&gt; c &gt;&gt; d;
    test.push_back(a);
    test.push_back(b);
    test.push_back(c);
    test.push_back(d);
    s = test[0] + test [1];
    std::cout &lt;&lt; s &lt;&lt; std::endl;
    s = test[2] + test [3];
    std::cout &lt;&lt; s &lt;&lt; std::endl;
    s = test[4] + test [5];
    std::cout &lt;&lt; s &lt;&lt; std::endl;
    s = test[0] + test [5];
    std::cout &lt;&lt; s &lt;&lt; std::endl;
</code></pre>
<p>it shall print the sum of the pairs and the sum of the first and last number in 'test'. I did write and read stuff this way already with strings, but now when i use ints, it doesn't work ...</p>
<p>if i input '1 2 3 4' the output is '0 0 1 1'<br />
if i input '1 1 1 1' its the same.</p>
<p>please help me,<br />
thanks.</p>
<p>Benno</p>
</blockquote>
<p>sum of pairs:</p>
<pre><code>s = test[0] + test [1];
    std::cout &lt;&lt; s &lt;&lt; std::endl;
    s = test[1] + test [2];
    std::cout &lt;&lt; s &lt;&lt; std::endl;
    s = test[2] + test [3];
    std::cout &lt;&lt; s &lt;&lt; std::endl;
</code></pre>
<p>so you dont need s[5].</p>
<pre><code>std::vector&lt;int&gt; test;//not initiallly fillng with 5 zeros
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2385924</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2385924</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sat, 01 Mar 2014 12:41:20 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Primer 3.3.3 on Sat, 01 Mar 2014 12:48:56 GMT]]></title><description><![CDATA[<p>oh ya the pushback function adds to the end <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 />
thanks man, works now.</p>
<pre><code>std::vector&lt;int&gt; test;
    int a, b, c, d, e, s;
    std::cin &gt;&gt; a &gt;&gt; b &gt;&gt; c &gt;&gt; d;
    test.push_back(a);
    test.push_back(b);
    test.push_back(c);
    test.push_back(d);
    test.push_back(e);
    s = test[0] + test [1];
    std::cout &lt;&lt; s &lt;&lt; std::endl;
    s = test[2] + test [3];
    std::cout &lt;&lt; s &lt;&lt; std::endl;
    s = test[0] + test [3];
    std::cout &lt;&lt; s &lt;&lt; std::endl;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2385926</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2385926</guid><dc:creator><![CDATA[hihohohi]]></dc:creator><pubDate>Sat, 01 Mar 2014 12:48:56 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Primer 3.3.3 on Sat, 01 Mar 2014 12:52:41 GMT]]></title><description><![CDATA[<p>If you want to optimize try using std::vector::reserve. It allocates memory for n elements, but the size stays at the old value (in this case 0), so push_back will result in the way you need it.</p>
<p>But in this special case it might be no optimization due to too less values. Long story short, you wont need it <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/2385929</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2385929</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Sat, 01 Mar 2014 12:52:41 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Primer 3.3.3 on Sat, 01 Mar 2014 12:58:10 GMT]]></title><description><![CDATA[<p>Skym0sh0 schrieb:</p>
<blockquote>
<p>If you want to optimize try using std::vector::reserve. It allocates memory for n elements, but the size stays at the old value (in this case 0), so push_back will result in the way you need it.</p>
<p>But in this special case it might be no optimization due to too less values. Long story short, you wont need it <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>i will keep that in mind for later tasks <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 />
thanks</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2385931</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2385931</guid><dc:creator><![CDATA[hihohohi]]></dc:creator><pubDate>Sat, 01 Mar 2014 12:58:10 GMT</pubDate></item></channel></rss>