check if cin didn 27t get int

Solutions on MaxInterview for check if cin didn 27t get int by the best coders in the world

showing results for - "check if cin didn 27t get int"
Sophia
23 Jun 2019
1while (std::cout << "Enter a number" && !(std::cin >> num)) {
2    std::cin.clear(); //clear bad input flag
3    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); //discard input
4    std::cout << "Invalid input; please re-enter.\n";
5}