Thank you both! The first approach [cin.get()] serves the intended purpose,
but requires that the user press ENTER. The second approach
[system("pause")] does exactly what I wanted, but it's seriously
non-portable.
As an exercise for my own education, let me rephrase the question. Suppose
I have an application that allows the user to enter a command by pressing a
single key on the keyboard. How would I accept the command into a char
variable?
- Bob
Serge Baltic - 27 Feb 2005 18:18 GMT
BA> As an exercise for my own education, let me rephrase the question.
BA> Suppose I have an application that allows the user to enter a
BA> command by pressing a single key on the keyboard. How would I
BA> accept the command into a char variable?
1) getch(), that's for plain C ;)
2) Maybe this:
char ch;
cin >> ch;

Signature
Serge
Hendrik Schober - 03 Mar 2005 01:36 GMT
> [...] Suppose
> I have an application that allows the user to enter a command by pressing a
> single key on the keyboard. How would I accept the command into a char
> variable?
I don't think you can do this portably in C++.
> - Bob
Schobi

Signature
SpamTrap@gmx.de is never read
I'm Schobi at suespammers dot org
"The presence of those seeking the truth is infinitely
to be prefered to those thinking they've found it."
Terry Pratchett
Julie - 03 Mar 2005 16:43 GMT
> As an exercise for my own education, let me rephrase the question. Suppose
> I have an application that allows the user to enter a command by pressing a
> single key on the keyboard. How would I accept the command into a char
> variable?
There isn't a portable solution. You either must accept key+enter or resort to
non-portable/platform-specific solutions.