Skip to content

Instantly share code, notes, and snippets.

@tmplt
Created July 5, 2014 01:14
Show Gist options
  • Select an option

  • Save tmplt/66bfff81e20ab466405e to your computer and use it in GitHub Desktop.

Select an option

Save tmplt/66bfff81e20ab466405e to your computer and use it in GitHub Desktop.
while (!(cin >> x)) {
cout << "error: something went wrong!" // alert user
cin.clear();
cin.ignore(1000, '\n'); // discard non-type (if x is a specific type) value in input buffer
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment