Re: std::cin and disabling canonical line processing (buffering)
- From: "Tom Widmer [VC++ MVP]" <tom_usenet@xxxxxxxxxxx>
- Date: Fri, 15 Jul 2005 13:59:44 +0100
Harold Bamford wrote:
I would like to read from cin one character at a time (eg, cin.get(thisChar) or the like) and not have to wait for the user to enter a carriage return.
On Unix or Cygwin, I would use tcgetattr/tcsetattr to turn off buffering and echoing on file descriptor 0 (STDIN) but this doesn't seem to be available in VC++ 7.1
What's the trick?
You could try something along these lines:
#include <windows.h> #include <iostream>
int main()
{
HANDLE inputHandle = GetStdHandle(STD_INPUT_HANDLE);
BOOL b = SetConsoleMode(inputHandle, 0); char c;
while(std::cin.get(c))
{
if (c == 'x')
break;
std::cout << c << " typed" << std::endl;
}
}Also, look at the rest of the Console functions, which you might prefer to deal with directly.
Tom .
- Follow-Ups:
- Re: std::cin and disabling canonical line processing (buffering)
- From: Harold Bamford
- Re: std::cin and disabling canonical line processing (buffering)
- From: Harold Bamford
- Re: std::cin and disabling canonical line processing (buffering)
- References:
- std::cin and disabling canonical line processing (buffering)
- From: Harold Bamford
- std::cin and disabling canonical line processing (buffering)
- Prev by Date: Re: Bug in hash_map/compiler?
- Next by Date: Re: Bug in hash_map/compiler?
- Previous by thread: std::cin and disabling canonical line processing (buffering)
- Next by thread: Re: std::cin and disabling canonical line processing (buffering)
- Index(es):
Relevant Pages
|
Loading