I\'m trying to use safe practices in handling input with numbers only in C++, so I use a stringstream object as so:
#include #include
cout << "First integer: "; getline(cin, input); sstream.str(input); sstream >> first; // state of sstream may be eof cout << "Second integer: "; getline(cin, input); sstream.str(input); sstream.clear(); // clear eof state sstream >> second; // input from sstream