📅  最后修改于: 2022-03-11 14:44:51.862000             🧑  作者: Mango
while (std::cout << "Enter a number" && !(std::cin >> num)) {
std::cin.clear(); //clear bad input flag
std::cin.ignore(std::numeric_limits::max(), '\n'); //discard input
std::cout << "Invalid input; please re-enter.\n";
}