title: How to store a text file into a vector (C++)
body: <p>I need help storing text from a text file into a vector.</p>
  
  <p>The text file is called "names.txt" and it has the following data</p>
  
  <pre><code>salman
  mahmoud
  ahmad
  ghadeer
  raghad
  abdullah
  faisal
  </code></pre>
  
  <p>The text below is my code</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  int main ()
  {
      vector&lt;string&gt; STRING;
      ifstream infile;
  
      infile.open ("names.txt");
  
      for(size_t i = 0; i &lt; 7; i++)
      {
          getline (infile, STRING[i]);
          cout &lt;&lt; STRING[i];
      }
  
      infile.close();
  
      return 0;
  }
  </code></pre>
  
  <p>Everytime I run the program, I get the following error message</p>
  
  <p><a href="https://i.stack.imgur.com/hNnNb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hNnNb.png" alt="Visual Studio Error Message"></a></p>