title: How does the capacity of std::vector grow automatically? What is the rate?
body: <p>I had been going through the Book:
  <code>C++ Primer, Third Edition By Stanley B. Lippman, Josée Lajoie</code>, found 1 mistake in the program given under the <code>Article 6.3 How a vector Grows Itself</code>, this program missed a &quot;&lt;&quot; in the <code>cout</code>s:</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;vector&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  int main() {
      vector&lt;int&gt; ivec;
      cout &lt; &quot;ivec: size: &quot; &lt; ivec.size() &lt; &quot; capacity: &quot;  &lt; ivec.capacity() &lt; endl;
      
      for (int ix = 0; ix &lt; 24; ++ix) {
          ivec.push_back(ix);
          cout &lt; &quot;ivec: size: &quot; &lt; ivec.size()
          &lt; &quot; capacity: &quot;  &lt; ivec.capacity() &lt; endl;
      }    
  }
  </code></pre>
  <p>Later within that article:</p>
  <blockquote>
  <p>&quot;Under the Rogue Wave implementation, both the size and the capacity
  of ivec after its definition are 0. On inserting the first element,
  however, ivec's capacity is 256 and its size is 1.&quot;</p>
  </blockquote>
  <p>But, on correcting and running the code i get the following output:</p>
  <hr />
  <pre><code>ivec: size: 0 capacity: 0
  ivec[0]=0 ivec: size: 1 capacity: 1
  ivec[1]=1 ivec: size: 2 capacity: 2
  ivec[2]=2 ivec: size: 3 capacity: 4
  ivec[3]=3 ivec: size: 4 capacity: 4
  ivec[4]=4 ivec: size: 5 capacity: 8
  ivec[5]=5 ivec: size: 6 capacity: 8
  ivec[6]=6 ivec: size: 7 capacity: 8
  ivec[7]=7 ivec: size: 8 capacity: 8
  ivec[8]=8 ivec: size: 9 capacity: 16
  ivec[9]=9 ivec: size: 10 capacity: 16
  ivec[10]=10 ivec: size: 11 capacity: 16
  ivec[11]=11 ivec: size: 12 capacity: 16
  ivec[12]=12 ivec: size: 13 capacity: 16
  ivec[13]=13 ivec: size: 14 capacity: 16
  ivec[14]=14 ivec: size: 15 capacity: 16
  ivec[15]=15 ivec: size: 16 capacity: 16
  ivec[16]=16 ivec: size: 17 capacity: 32
  ivec[17]=17 ivec: size: 18 capacity: 32
  ivec[18]=18 ivec: size: 19 capacity: 32
  ivec[19]=19 ivec: size: 20 capacity: 32
  ivec[20]=20 ivec: size: 21 capacity: 32
  ivec[21]=21 ivec: size: 22 capacity: 32
  ivec[22]=22 ivec: size: 23 capacity: 32
  ivec[23]=23 ivec: size: 24 capacity: 32
  </code></pre>
  <hr />
  <p>Is the capacity increasing with the formula <code>2^N</code> where <code>N</code> is the initial capacity? Please explain.</p>