Re: std::cin and disabling canonical line processing (buffering)
- From: "Harold Bamford" <HaroldBamford@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 19 Jul 2005 15:38:08 -0700
Tom,
Well I tried this and it almost works. Unfortunately, it looks like
newline/carriage-return filtering is still happening. I can get any character
immediately except for \r or \n. I cannot seem to get a newline (^J) no
matter what, and 2 consecutive \r chars are needed to get one response out of
std::cin.get(c)
I've looked throughout the console function documentation and I cannot find
any reference to turning this behaviour off.
Sorry to be such a pain, but I could still use another clue.
Thanks.
-- Harold
"Tom Widmer [VC++ MVP]" wrote:
> 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: Tom Widmer [VC++ MVP]
- Re: std::cin and disabling canonical line processing (buffering)
- References:
- std::cin and disabling canonical line processing (buffering)
- From: Harold Bamford
- Re: std::cin and disabling canonical line processing (buffering)
- From: Tom Widmer [VC++ MVP]
- std::cin and disabling canonical line processing (buffering)
- Prev by Date: Re: Some help with parsing?
- Next by Date: Compilation Errors in VC++ 5.0
- Previous by thread: Re: 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