delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/12/25/11:27:38

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
Date: Tue, 25 Dec 2001 18:21:07 +0200
From: "Eli Zaretskii" <eliz AT is DOT elta DOT co DOT il>
Sender: halo1 AT zahav DOT net DOT il
To: "Cody" <cody1 AT ktsnet DOT com>
Message-Id: <3942-Tue25Dec2001182106+0200-eliz@is.elta.co.il>
X-Mailer: emacs 21.1.50 (via feedmail 8 I) and Blat ver 1.8.9
CC: djgpp AT delorie DOT com
In-reply-to: <3c24f3be@leia.ktsnet.com> (cody1@ktsnet.com)
Subject: Re: bug in djgpp 3.0.2? surely it's my fault
References: <3c24f3be AT leia DOT ktsnet DOT com>
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> 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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019