title: Read from file line by line and parse to vector a lot of ints in c++
body: <p>I have seen a lot of similar posts regarding very similar cases but my case is a bit different. I'm a newbie to c++, so any help would be appreciated.</p>
  
  <p>I have a large file full of lines full of integers. Each number is separated by blank spaces. I need diferent lines to stay seperate, i don't want to read all the file on one go. I want to read line by line and parse each line in to a vector of integers. The code I've got is this:</p>
  
  <pre><code>int main () {
    string line;
    ifstream myfile;
    myfile.open ("numbers.txt");
    vector&lt;int&gt; vec1;
    int const2=0;
    int a;
    while ( getline (myfile,line) ){ // I understand that this reads line 
                                     // by line and stores the string to "line"
      while (line &gt;&gt; a){  // this part is the one i can't get right, i 
                          // want to push_back every int from
                          // the string to vec1 but doesn't work
        vec1.push_back(a); 
        // More stuff
      }
      // more stuff
    }
    myfile.close();   
    return 0;
  }
  </code></pre>