K
Kevin W.
I'm writing a simple Unix console app. I need to take an input of a
single character from the user and discard the rest.
If I have:
char c;
cin >> c;
And the user types the letter 'a', then presses Enter, 'a' gets put into c
as I want. BUT, Enter remains as the next character in the stream, so if
I then do a getline(cin, word), I get an empty string in word. The other
requirement I need is that if the user just presses Enter without entering
a letter, c should be assigned to '\n'.
Ideally, it should process the character (whatever it is) without the user
having to press Enter.
single character from the user and discard the rest.
If I have:
char c;
cin >> c;
And the user types the letter 'a', then presses Enter, 'a' gets put into c
as I want. BUT, Enter remains as the next character in the stream, so if
I then do a getline(cin, word), I get an empty string in word. The other
requirement I need is that if the user just presses Enter without entering
a letter, c should be assigned to '\n'.
Ideally, it should process the character (whatever it is) without the user
having to press Enter.