Mail Archives: djgpp/1997/01/19/22:25:08
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
- Raw text -