Do you mean that you want to grab characters from the terminal as soon
as the key is pressed rather than waiting for them to hit enter? If so,
you need to set raw input mode on the stream. Now I don’t know if this
works for cin/cout but here’s how you do it with C on a file descriptor.
I would expect that cin/cout/cerr are reading/writing from 0/1/2 so this
might work.
int raw(int fd)
{
struct termios termios_p;
if( tcgetattr( fd, &termios_p ) )
return( -1 );
termios_p.c_cc[VMIN] = 1;
termios_p.c_cc[VTIME] = 0;
termios_p.c_lflag &= ~( ECHO|ICANON|ECHOE|ECHOK|ECHONL );
termios_p.c_oflag &= ~( OPOST );
return( tcsetattr( fd, TCSADRAIN, &termios_p ) );
}
int unraw(int fd)
{
struct termios termios_p;
if( tcgetattr( fd, &termios_p ) )
return( -1 );
termios_p.c_lflag |= ( ECHO|ICANON|ISIG|ECHOE|ECHOK|ECHONL );
termios_p.c_oflag |= ( OPOST );
return( tcsetattr( fd, TCSADRAIN, &termios_p ) );
}
Hope that works…There’s probably an officially sanctioned C++ way to do
it but I don’t know how myself.
cheers,
Kris
john@broadcast.ipv7.net wrote:
I need to gather terminal input (console, pterm or
whatever…) using cin (an iostream) WITHOUT
buffering.
Something similar to the getch() function found
in some dos compilers.
Maybe there are some way to disable buffering
in the basic_streambuf present inside cin?
Thanks in advance.
–
John [ipv7.net]
–
Kris Warkentin
kewarken@qnx.com
(613)591-0836 x9368
“Computer science is no more about computers than astronomy is about telescopes”
–E.W.Dijkstra