fork download
  1. #include <iostream>
  2. #include <limits>
  3. int main()
  4. {
  5. using namespace std;
  6.  
  7. int n;
  8. cout << "how many names do you want to register\n";
  9. cin >> n;
  10.  
  11. if (!cin) {
  12. cin.clear(); // unset the error flag
  13. cin.ignore( numeric_limits<streamsize>::max(), '\n'); // get rid of the bad input
  14. cout<<"Please input an integer value\n";
  15. }
  16.  
  17. cin >> n;
  18. cout << "You've entered " << n << '\n';
  19. }
Success #stdin #stdout 0s 2728KB
stdin
something that's not a number
42
stdout
how many names do you want to register
Please input an integer value
You've entered 42