CODE int, string

What is the code to bring up an error message when someone types in a letter into an integer section in a console application?
Have you even given it a shot yet?
Show me the code you've got trying to accomplish this task, and I will gladly assist you.
The extraction operator >> returns the stream you extracted from, and streams can be implicitly converted to bool to check their status. You can, for example, write if(std::cin >> MyInt), and if you end up in the else clause you need to use clear() on cin and tell the user to try again. You can use a looping structure to repeatedly prompt the user until they enter valid numeric input.
Topic archived. No new replies allowed.