title: Initialize empty vector of vectors with elements of vector of vectors
body: <p>I have a function which shall initialize an empty vector of vectors from type string with certain elements from an given vector of vectors from type string. My syntax looks like this</p>
  
  <pre><code>std::vector&lt;std::vector&lt;std::string&gt;&gt; extract_data_on_userid(const std::vector&lt;std::vector&lt;std::string&gt;&gt; &amp;array, std::vector&lt;std::string&gt; &amp;user_ids, const int nr_of_events)
  {
    std::vector&lt;std::vector&lt;std::string&gt;&gt; data_extract;
    int event_iterator = 0;
    int user_id_iterator = 0;
  
    // While loops which extracts the events based on user IDs
    while (event_iterator &lt;= nr_of_events)
    {
      // While loop which finds specified user id in an event
      while (user_id_iterator &lt; array[0].size())
      {
        if (check_id(user_ids, array[0][user_id_iterator]))
        {
          for (size_t i = 0; i &lt; array.size(); i++)
          {
            data_extract[i].push_back(array[i][user_id_iterator]);
          }
        }
        user_id_iterator++;
      }
  
      event_iterator++;
    }
  
    return data_extract;
  }
  </code></pre>
  
  <p>The given vector consists on varying number of string vectors (at least 2). My method shall search for certain UserIDs in </p>
  
  <pre><code>check_id(user_ids, array[0][user_id_iterator])
  </code></pre>
  
  <p>an then push the relevant event (user_id_iterator) in a new 2D Vector for all 1D Vectors </p>
  
  <pre><code>vector[i:in][user_id_iterator]
  </code></pre>
  
  <p>Into the newly initiated vector </p>
  
  <pre><code>std::vector&lt;std::vector&lt;std::string&gt;&gt; data_extract;
  </code></pre>
  
  <p>over the for loop.</p>
  
  <pre><code> for (size_t i = 0; i &lt; array.size(); i++)
      {
        data_extract[i].push_back(array[i][user_id_iterator]);
      }
  </code></pre>
  
  <p>It all does work as expected until the elements of the vectors[i:in] in row [user_id_iterator] shall be pushed into the emtpy vectors. </p>
  
  <p>Do I intially have to initialize all 1D vectors in the 2D Vector data_extract? What is the correct syntax to fill an empty vector of vectors which certain elements from a filled vector of vectors? 
  I receive an exception (segmentation fault) because the emtpy vector is not initialized correctly. </p>