I did the following method as in http://www.parashift.com/c++-faq-lite/input-output.html to validate, but it does not work:
if (!(cin >> hex >>address1))
{
cout << "Invalid input.";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
It keeps carrying the remaining input to the next input, thus making the next input cannot be typed in by user, even the std::cin is cleared and ignored.
I guess I’d do something like this:
There are a lot of variations, but the three steps I’d follow would be: