Message-ID: <32E3091F.5450@dmv.com> Date: Sun, 19 Jan 1997 21:56:47 -0800 From: Pyro Technic Reply-To: invid AT dmv DOT com Organization: Happy 'N Snappy PC Repair MIME-Version: 1.0 To: mail-list Subject: Re: getch() and getche() References: <32E251B8 DOT 1C3E AT dmv DOT com> <32E2ADC2 DOT 1579 AT cs DOT com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit John M. Aldrich wrote: > > Pyro Technic wrote: > > > > i don't no if NE1 else has noticed this but there is a very annoying > > featire with getch() and getche(). as a newbie i'd much appreciate NE1 > > who could point out how to fix it. > > Under gcc, stdout is line buffered. It only gets flushed when you print > a newline or call a stdio input function. However, getch() and getche() > are conio functions which interface directly with the BIOS. The two are > not directly compatible and will cause problems if you use them > together. Please note that this is NOT a bug in djgpp, but a feature of > ANSI C/C++. You should never mix stdio and conio functions in portable > code. > > There are several ways to solve your problem without using a newline: > > 1) Manually flush stdout after the cout call. > > cout << "Y for yes or N for No: "; > fflush( stdout ); > answer = getche(); > > 2) Use cprinf (a conio function) instead of cout. > > cprintf( "Y for yes or N for No: " ); > answer = getche(); > > 3) Use stdio input functions. > > cout << "Y for yes or N for No: "; > cin >> answer; > > Of course, here you'll have to press Enter to get your key accepted. > > -- > --------------------------------------------------------------------- > | John M. Aldrich, aka Fighteer I | fighteer AT cs DOT com | > | Call me for your free AOL disk! | http://www.cs.com/fighteer | > | Chain letters, work-at-home schemes, free long distance, etc., | > | are ILLEGAL! Keep the Internet litter-free... don't SPAM. | > --------------------------------------------------------------------- tanxs much, U guys R just about the nicest smartest bunch of people i never met. :> Pyro