Possible Duplicate:
How to read integers from a file, line by line in C++
Please anyone can suggest me how to take input of integers until a newline in C++.
Suppose the input stream is
10 10 10 10 10 10 10 10 10 10, followed by a newline in C++.
Possible Duplicate:
How to read integers from a file, line by line in C++
Please anyone can suggest me how to take input of integers until a newline in C++.
Suppose the input stream is
10 10 10 10 10 10 10 10 10 10, followed by a newline in C++.
std::string the_string;
std::getline(the_stream, the_string);
std::istringstream iss(the_string);
for (int n; iss >> n; )
{
// do something with n
}
Likely duplicate of: How to read groups of integers from a file, line by line in C++
If you want to deal in a line per line basis:
int main() { std::string line; std::vector< std::vector<int> > all_integers; while ( getline( std::cin, line ) ) { std::istringstream is( line ); all_integers.push_back( std::vector<int>( std::istream_iterator<int>(is), std::istream_iterator<int>() ) ); } }