title: Reading line from text file and putting the strings into a vector?
body: <p>I am trying to read each line of a textfile which each line contains one word and put those words into a vector. How would i go about doing that?</p>
  
  <p>This is my new code: I think there is still something wrong with it.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  int main()
  {
      std::string line;
      vector&lt;string&gt; DataArray;
      vector&lt;string&gt; QueryArray;
      ifstream myfile("OHenry.txt");
      ifstream qfile("queries.txt");
  
      if(!myfile) //Always test the file open.
      {
          cout&lt;&lt;"Error opening output file"&lt;&lt;endl;
          system("pause");
          return -1;
      }
      while (std::getline(qfile, line))
      {
          QueryArray.push_back(line);
      }
      if(!qfile) //Always test the file open.
      {
          cout&lt;&lt;"Error opening output file"&lt;&lt;endl;
          system("pause");
          return -1;
      }
  
      while (std::getline(qfile, line))
      {
          QueryArray.push_back(line);
      }
  
      cout&lt;&lt;QueryArray[0]&lt;&lt;endl;
      cout&lt;&lt;DataArray[0]&lt;&lt;endl;
  
  }
  </code></pre>