The istream extraction operator will automatically skip the blank lines in the input, so the read_ints() function in the below example will return a vector of the whitespace (including the newlines) separated values in the input stream.
#include <vector>
#include <iostream>
using namespace std;
vector<int>
read_ints(istream & is)
{
vector<int> results;
int value;
while ( is >> value )
{
results.push_back(value);
}
return results;
}
int
main(int argc, char * argv[])
{
vector<int> results = read_ints(cin);
for ( vector<int>::const_iterator it = results.begin(); it != results.end(); ++it )
cout << *it << endl;
return 0;
}
The above code stops reading if any of the input cannot be parsed as an int and allows integers to be separated by spaces as well as newlines, so may not exactly match the requirements of the question.