c 2b 2b check if cin got the wrong type

Solutions on MaxInterview for c 2b 2b check if cin got the wrong type by the best coders in the world

showing results for - "c 2b 2b check if cin got the wrong type"
Juline
26 Mar 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}
similar questions
queries leading to this page
c 2b 2b check if cin got the wrong type