title: STL vector reserve() and copy()
body: <p>Greetings,</p>
  
  <p>I am trying to perform a copy from one vector (vec1) to another vector (vec2) using the following 2 abbreviated lines of code (full test app follows):</p>
  
  <pre><code>vec2.reserve( vec1.size() );
  copy(vec1.begin(), vec1.end(), vec2.begin());
  </code></pre>
  
  <p>While the call to vec2 sets the capacity of vector vec2, the copying of data to vec2 seems to not fill in the values from vec1 to vec2.</p>
  
  <p>Replacing the copy() function with calls to push_back() works as expected.</p>
  
  <p>What am I missing here?</p>
  
  <p>Thanks for your help. vectest.cpp test program followed by resulting output follows.</p>
  
  <p>Compiler: gcc 3.4.4 on cygwin.</p>
  
  <h2>Nat</h2>
  
  <pre><code>/**
   * vectest.cpp
   */
  
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  int main()
  {
      vector&lt;int&gt; vec1;
      vector&lt;int&gt; vec2;
  
      vec1.push_back(1);
      vec1.push_back(2);
      vec1.push_back(3);
      vec1.push_back(4);
      vec1.push_back(5);
      vec1.push_back(6);
      vec1.push_back(7);
  
      vec2.reserve( vec1.size() );
      copy(vec1.begin(), vec1.end(), vec2.begin());
  
      cout &lt;&lt; "vec1.size()     = " &lt;&lt; vec1.size() &lt;&lt; endl;
      cout &lt;&lt; "vec1.capacity() = " &lt;&lt; vec1.capacity() &lt;&lt; endl;
  
      cout &lt;&lt; "vec1: ";
      for( vector&lt;int&gt;::const_iterator iter = vec1.begin(); iter &lt; vec1.end(); ++iter ) {
          cout &lt;&lt; *iter &lt;&lt; " ";
      }
      cout &lt;&lt; endl;
  
      cout &lt;&lt; "vec2.size()     = " &lt;&lt; vec2.size() &lt;&lt; endl;
      cout &lt;&lt; "vec2.capacity() = " &lt;&lt; vec2.capacity() &lt;&lt; endl;
      cout &lt;&lt; "vec2: ";
      for( vector&lt;int&gt;::const_iterator iter = vec2.begin(); iter &lt; vec2.end(); ++iter ) {
          cout &lt;&lt; *iter &lt;&lt; endl;
      }
  
      cout &lt;&lt; endl;
  }
  </code></pre>
  
  <hr>
  
  <p>output:</p>
  
  <pre><code>vec1.size()     = 7
  vec1.capacity() = 8
  vec1: 1 2 3 4 5 6 7 
  vec2.size()     = 0
  vec2.capacity() = 7
  vec2: 
  </code></pre>