title: Reading space-separated numbers from cin in C++
body: <p>I have to put the numbers from each line of input into different vectors without knowing how many numbers there will be in one line of input. For example:</p>
  <pre><code>1 2 3
  4 5 6 -7
  </code></pre>
  <p>should result in</p>
  <pre><code>a = {1, 2, 3};
  b = {4, 5, 6, -7};
  </code></pre>
  <p>Note that the number of integers in each line is unknown.</p>
  <p>I've tried using <code>stringstream</code> but for some reason it didn't work for two lines of input:</p>
  <pre><code>int main() {
    vector&lt;int&gt; a, b;
  
    string c;
    int number;
    stringstream lineOfInput;
  
    getline(cin, c);
    lineOfInput.str(c);
    c = &quot;&quot;;
  
    while (lineOfInput &gt;&gt; number) {
      a.push_back(number);
    }
  
    getline(cin, c);
    lineOfInput.str(c);
    c = &quot;&quot;;
  
    while (lineOfInput &gt;&gt; number) {
      b.push_back(number);
    }
  
    return 0;
  }
  </code></pre>
  <p>The first vector is filled normally, but the second doesn't. Is there a good way to extract numbers from lines (without using boost library) and what's the problem with my code?</p>