title: Issues with vector resizing in C++
body: <p>I may be wrong but I was under the impression that the number of elements in a vector in C++ can be altered dynamically? However, when I run the following piece of code I do not get the result I expect.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  int main()
  {
      vector &lt;int&gt; vec(10);
      for(int i=0; i&lt;10; i++){
          vec[i]=i+1;
          cout &lt;&lt; vec[i] &lt;&lt; endl;
      }
      cout &lt;&lt; "the length of this vector is " &lt;&lt; vec.size() &lt;&lt; endl;
      for(int i=0; i&lt;20; i++){
          vec[i]=i+1;
          cout &lt;&lt; vec[i] &lt;&lt; endl;
      }
      cout &lt;&lt; "the length of this vector is " &lt;&lt; vec.size() &lt;&lt; endl;
  }
  </code></pre>
  
  <p>The output looks like</p>
  
  <pre><code>1
  2
  3
  4
  5
  6
  7
  8
  9
  10
  the length of this vector is 10
  1
  2
  3
  4
  5
  6
  7
  8
  9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  the length of this vector is 10
  </code></pre>
  
  <p>I had expected the second <code>vec.size()</code> to give me a value of twenty? I am looking for an object in C++ which behaves something like a list in Python.</p>