Advertisement
axyd

c++ Only Accept Numbers

Apr 14th, 2016
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.21 KB | None | 0 0
  1. if (cin.fail()){
  2.     cout << "\n\t\t/!\\ You did not enter an integer /!\\\n";          
  3.     cin.clear(); // get rid of failure state           
  4.     cin.ignore(numeric_limits<streamsize>::max(), '\n'); // discard 'bad' character(s)
  5. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement