title: Difference between "size" and "capacity" in c++ string?
body: <p>I have this snippet from Thinking in C++.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  int main ()
  {
  string bigNews("I saw Elvis in a UFO. ");
  cout &lt;&lt; bigNews &lt;&lt; endl;
   bigNews.insert(0, " thought I ");
  cout &lt;&lt; bigNews &lt;&lt; endl;
  cout &lt;&lt; "Size = " &lt;&lt; bigNews.size() &lt;&lt; endl;
  cout &lt;&lt; "Capacity = "
  &lt;&lt; bigNews.capacity() &lt;&lt; endl;
  bigNews.append("I've been working too hard.");
  cout &lt;&lt; bigNews &lt;&lt; endl;
  cout &lt;&lt; "Size = " &lt;&lt; bigNews.size() &lt;&lt; endl;
  cout &lt;&lt; "Capacity = "
  &lt;&lt; bigNews.capacity() &lt;&lt; endl;
    return 0;
  }
  </code></pre>
  
  <p>And I get output as shown below:</p>
  
  <pre><code>I saw Elvis in a UFO. 
   thought I I saw Elvis in a UFO. 
  Size = 33
  Capacity = 44
   thought I I saw Elvis in a UFO. I've been working too hard.
  Size = 60
  Capacity = 88
  </code></pre>
  
  <p>I can figure out why the size increases, but I am not able to make out how the Capacity increases?</p>
  
  <p>What i know is Capacity is the string buffer where we can Pushback, but how that space is allocated?</p>