Mail Archives: djgpp/2000/10/08/06:31:11
> From: "David Grant" <dgrant79 AT hotmail DOT com>
> Newsgroups: comp.os.msdos.djgpp
> Date: Sun, 8 Oct 2000 02:20:01 -0700
>
> Can anyone tell me how to get a character from the screen (I mean keyboard)
> without requiring a carriage return? cin won't work, and neither will
> "&istream get(char c)" funtion.
The problem is that by default, stdin is in line-buffered mode.
Unfortunately, there's no ANSI standard way of getting a non-default
behavior that you want.
If you want your code to be portable to Unix environments, use the
termios functions to switch the standard input into a single-character
mode. The docs of the DJGPP library describes the termios
capabilities, see the node "Termios functions" in libc.info.
The DJGPP archives, http://www.delorie.com/djgpp/mail-archives/, have
some messages relevant to this issue (search for "termios") which can
help you with details.
Note that termios might not be portable to other DOS/Windows
compilers, with the notable exception of Cygwin. But it is portable
to Unix and GNU/Linux systems.
Alternatively, you could switch stdin into raw mode with a call to the
library function setmode. This is probably DJGPP-specific (although
setmode exists in other compilers). The library docs of setmode
should explain its effect and give some examples.
- Raw text -