I\'m very new to this C++ world and trying write a input validation function for numeric password. This is what I got so far:
#include
#incl
If there is a failure to convert then the stream itself evaluates to false so you can do this:
int get_int() {
int i;
std::cout << "Please enter a number: " << std::endl;
while(!(std::cin >> i)) {
std::cin.clear(); //clear flags
//discard bad input
std::cin.ignore(std::numeric_limits::max());
std::cout << "Incorrect, must be numeric: " << std::endl;
}
return i;
}