title: C++ dynamic vector of pairs
body: <p>I need to dynamically allocate an array of 5 <code>vectors</code> of <code>pairs</code>. This code snippet is supposed to add first elements to all 5 <code>vectors</code>:</p>
  
  <pre><code>std::vector&lt;std::pair&lt;int, int&gt;&gt; * arr = new std::vector&lt;std::pair&lt;int, int&gt;&gt;[5];
  for (int i = 0; i &lt; 5; i++) {
      arr[i].push_back(std::make_pair(i+1, i+11));
  }
  </code></pre>
  
  <p>But it adds only 1 element to <code>arr[0]</code> vector</p>
  
  <pre><code>for (auto el : *arr) {
      std::cout &lt;&lt; el.first &lt;&lt; ", " &lt;&lt; el.second &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>Printing out gives <code>1, 11</code><br>
  What I need is </p>
  
  <pre><code>1, 11
  2, 12
  3, 13
  4, 14
  5, 15
  </code></pre>
  
  <p>Please give me some hints. How to work with dynamic vector of pairs?</p>
  
  <p><strong>EDIT:</strong> Vector of vectors is one possible way. However, I want to use an array of vectors.</p>