Mail Archives: djgpp/2001/12/25/11:27:38
> From: "Cody" <cody1 AT ktsnet DOT com>
> Newsgroups: comp.os.msdos.djgpp
> Date: Sat, 22 Dec 2001 14:47:36 -0600
>
> int get_key();//problematic function
>
> int main() {
> cout<<get_key()<<endl;
> return EXIT_SUCCESS;
> }
>
> int get_key() {
> ifstream input("con");//of course "con" is non-standard, but it's still a
> "file", so there should be no problem
> return input.get();//get() creates infinite loop (well, not inf. loop, but
> it waits until I press EOF [Cntr+Z]).
> //get() is supposed to return next key, not return next key only after EOF
> has been pressed.
Does it stop waiting if you press [Enter] right after the first key?
If so, what you see is the normal, so-called ``cooked'' operation of
a terminal: the read operation doesn't return until you press Enter.
That's because by default, the terminal device is in line-input
mode. I believe this is so on Unix as well.
To get a single-key input, you need to use the termios functions to
switch the terminal into raw mode. The library reference has the
details.
- Raw text -