fork(1) download
  1. #include <iostream>
  2. #include <limits>
  3.  
  4. int main()
  5. {
  6. using namespace std;
  7.  
  8. int n;
  9. while ( !( cin >> n ) || n < 0 )
  10. {
  11. cout << "Bad input" << endl;
  12. cin.clear();
  13. cin.ignore( numeric_limits<std::streamsize>::max(), '\n' );
  14. }
  15.  
  16. cout << "You entered: " << n;
  17.  
  18. return 0;
  19. }
  20.  
Success #stdin #stdout 0s 15232KB
stdin
abc
-123
123
stdout
Bad input
Bad input
You entered: 123