title: Why are errors to insert a data after end of vector in c++
body: <pre><code>#include &lt;sstream&gt;
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  string** DataStorage;
  
  string line;
  vector&lt;vector&lt;string&gt;&gt; extractingData(200, vector&lt;string&gt;(10));
  vector&lt;vector&lt;string&gt;&gt; extractingData2(200, vector&lt;string&gt;(10));
  
  string pathExtract;
  string pathStorage;
  
  ofstream storageFile;
  ifstream storageFileRead;
  fstream extractingFile;
  fstream extractingFile2;
  
  
  void ReadData(fstream&amp; extractingFile, vector&lt;vector&lt;string&gt;&gt; extractingData, string pathExtract)
  {
      extractingFile.open(pathExtract, ios::in | ios::out | std::ios_base::app);
  
      int i = 0;
      int index;
      if (extractingFile.is_open())
      {
          while (getline(extractingFile, line))
          {
              istringstream iss(line);
              int j = 0;
              while (!iss.eof()){
                  iss &gt;&gt; extractingData[i][j];
                  j++;
              }
              i++;
          }
  
          extractingFile.close();
      }
  }
  
  
  int main() {
      pathExtract = "sample.txt";
      pathStorage = "mergedData.txt";
      ReadData(extractingFile, extractingData, pathStorage);
      ReadData(extractingFile2, extractingData2, pathExtract);
      mergeData(extractingData, extractingData2, pathStorage);
  
  }
  
  
  void mergeData(vector&lt;vector&lt;string&gt;&gt; extractingData, vector&lt;vector&lt;string&gt;&gt; extractingData2, string pathStorage){
  
      int i = 0;
      int j = 0;
      while (i&lt;extractingData.size())
      {
          while (extractingData[i][0] != extractingData2[j][0])
          {
              j++;
          }
          if (extractingData[i][0] == extractingData2[j][0])
          {
              //extractingData[i].insert
              extractingData[i].insert(extractingData[i].end(), extractingData2[j].pop_back()); // here is error
          }   
          i++;
      }
  
  //  storageFileRead.open(pathStorage, std::ios_base::out | std::ios_base::app);
      storageFileRead.open(pathStorage);
      i = 0;
      if (storageFileRead.is_open())
      {
          ofstream outFile(pathStorage);
          while (getline(storageFileRead, line)){
  
              std::vector&lt;int&gt;::const_iterator col;   
              for (col = extractingData[i].begin(); col !=extractingData[i].end(); ++col) { // here is errors, too
                  outFile &lt;&lt; *col;
                  }
              outFile &lt;&lt; endl;
              i++;
          }
      }
  }
  </code></pre>
  
  <p>I have a dataset like below in a text file named mergedData.txt</p>
  
  <pre><code>country OD DM              
  Croatia 36 15
  Spain 35 26
  Belgium 32 38
  USA 25 57
  France 24 29
  Estonia 24 19
  </code></pre>
  
  <p>and also new dataset is given in text file named sample.txt. </p>
  
  <pre><code>country VT
  Estonia 21%
  Belgium 26%
  Croatia 6%
  France 29%
  Spain 13%
  USA 42%
  </code></pre>
  
  <p>i want to add some new variable named VT(Volunteering Time) in the end of each lines like this.</p>
  
  <pre><code>country OD DM VT             
  Croatia 36 15 6
  Spain 35 26 13
  Belgium 32 38 26
  USA 25 57 42
  France 24 29 29
  Estonia 24 19 21
  </code></pre>
  
  <p>but there are some errors. i'll glad of any helps.</p>