Original Post
🔒 Locked
Bad Input (C++)
Advertisement
Just to expand on what Zipster was saying, the user being a moron puts the stream into a "fail" state which needs to be cleared before input can continue. check out the iostream documentation for more details. Zipster''s code invokes the implicit void* conversion operator on cin, which returns NULL if the stream is in a fail state.
Don''t listen to me. I''ve had too much coffee.
Don''t listen to me. I''ve had too much coffee.
#include "conio.h"
void main() //Or whatever your functions called
{
int myInput = getch();//Reads one character from the keyboard
//Now myInput holds the ASCII code for that character
if (myInput==13) //ASCII-value 13 which means [ENTER]
//[do_something]
}
void main() //Or whatever your functions called
{
int myInput = getch();//Reads one character from the keyboard
//Now myInput holds the ASCII code for that character
if (myInput==13) //ASCII-value 13 which means [ENTER]
//[do_something]
}
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement