title: How do vectors of vectors work?
body: <p>The answer <a href="https://stackoverflow.com/questions/849168/are-stdvector-elements-guaranteed-to-be-contiguous">here</a> says: </p>
  
  <blockquote>
    <p>From n2798 (draft of C++0x):
    The elements of a vector are stored contiguously, meaning that if v is
    a vector where T is some type other than bool, then it obeys the
    identity &amp;v[n] == &amp;v[0] + n for all 0 &lt;= n &lt; v.size().</p>
  </blockquote>
  
  <p>This program works: </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;iterator&gt;
  using namespace std;
  
  int main(){
    int k;
    cin &gt;&gt; k; cout &lt;&lt; endl &lt;&lt; "k = " &lt;&lt; k &lt;&lt; endl;
    ostream_iterator&lt;int&gt; oi(cout, " ");
    vector&lt;vector&lt;int&gt; &gt; vpi;
    while(k--)
    {
      vpi.push_back(vector&lt;int&gt;(istream_iterator&lt;int&gt;(cin), istream_iterator&lt;int&gt;()));
      cin.clear();
      cout&lt;&lt;"k = "&lt;&lt; k &lt;&lt;endl;
      copy(vpi[vpi.size()-1].begin(), vpi[vpi.size()-1].end(), oi);
      cout&lt;&lt;endl;
    }
  }
  </code></pre>
  
  <p>How can a vector store vectors contiguously, when the elements of a vector must have equal size and the size of vectors to be stored is not known in advance? </p>
  
  <p>I apologize if this has been asked before, I could not find it, if this is the case just drop me a link, please. </p>