That's because std::cin does input validation. You'll need to check the result of an input operation, and if there was a problem "ignore" unread characters and "clear" the error bits.
Code:#include <iostream> #include <limits> int main() { int n = 1; do { if (std::cin >> n) { std::cout << "Ok " << n << '\n'; } else { std::cout << "Not Ok\n"; std::cin.clear(); std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); } } while (n); }