title: How to read lines of text from file and put them into an array
body: <p>I created a text file <code>love.txt</code>:</p>
  
  <pre><code>i love you
  you love me
  </code></pre>
  
  <p>How do I store them into separate array, namely <code>line1</code> and <code>line2</code> and then display them out in console?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  int main()
  {
    string line1[30];
    string line2[30];
    ifstream myfile("love.txt");
    int a = 0;
    int b = 0;
    if(!myfile) 
    {
      cout&lt;&lt;"Error opening output file"&lt;&lt;endl;
      system("pause");
      return -1;
    }
    while(!myfile.eof())
    {
      getline(myfile,line1[a],' ');
      cout&lt;&lt;"1."&lt;&lt;line1[a]&lt;&lt;"\n";
      getline(myfile,line2[b],' ');
      cout&lt;&lt;"2."&lt;&lt;line2[b]&lt;&lt;"\n";
    }
  }
  </code></pre>