Keyboard Input

Hi

How to check whether the user did input a value to the program?

How do you check to see if the user did input anything at a cin command, if the use did not input a value how to show a message? i tried NULL but not working.
Last edited on
One option:
1
2
3
4
5
6
  string input;
  cin >> input;
  if (!cin) // if (input.empty()
    cout << "No input";
  else
    cout << "\nInput was " << input;

The same should for numbers as well
Topic archived. No new replies allowed.