title: Fill an array with getline loop
body: <p>Would like to fill an array one line at a time from the file "Hello.cpp". However if I do it the way below I fill the entire file [w] times instead of just grabbing one line from the file for each iteration of i. </p>
  
  <p>If I remove the { } from getline then the array is filled with the last line of "Hello.cpp" [w] times.</p>
  
  <p>I am not sure how to get a new [i] each time from the Hello.cpp file.</p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;fstream&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  int main() {
  int w=0;
  ifstream in("Hello.cpp"); 
  string s;
  while(getline(in, s))
       w=w+1; //first count the number of lines in the file for the array
  
  string a[w];//make an array big enough for the file
  for(int i = 0; i &lt; w ; i++) {
      ifstream in("Hello.cpp");
      string s;
      while(getline(in, s)){
          a[i] = s;
          cout &lt;&lt; i + 1 &lt;&lt; " " &lt;&lt; s &lt;&lt; endl;
     }
  }
  </code></pre>