I have seen other questions on SO in regards to validation of the format of input however am looking for a more specific answer for the issue i am having.
Currently, I am required to read in 2 integer values and store them as coordinates. I have used:
cin >> x >> y
int whitepsace int
Read the two values into two
std::strings first. This will read in any whitespace-delimited text, without putting
std::cin into a failed state.
Once the two words are read in, for each one construct a
operator>> to attempt to parse it into an
fail() to check whether the conversion failed, or not, and if the entire
std::istringstream was consumed.
std::istringstream is not in failed state, and
eof, then the entire word was succesfully parsed into the
This is not, of course, the only way to do it, but is probably the most simple one, and the approach is limited to using basic C++ library classes, nothing too fancy.