Mail Archives: djgpp-workers/1999/05/09/05:18:16
Given the forwarded message, should we add fflush(stdout+stderr) to
`getch', like we already did in `filbuf'? Or would programs that use
`getch' hate us for flushing the streams for every input character?
---------- Forwarded message ----------
Date: Thu, 06 May 1999 00:01:42 +0800
From: Chong Kai Xiong <w_velocity AT yahoo DOT com>
To: djgpp AT delorie DOT com
Newgroups: comp.os.msdos.djgpp
Subject: Quirky getch()
I was testing my vector class library when I discovered some very
strange things about getch(). I thought my library was buggy until I
wrote this test program:
#include <conio.h>
#include <iostream.h>
int main() {
clrscr();
cout << "Hello World\n";
cout << "Sing along!";
getch();
return 0;
}
Normally, we (at least I did :) would expect "Hello World" and "Sing
along!" to be printed before the program pauses to wait for a keypress;
The strange thing is, it doesn't. The program prints "Hello World" and
then waits for a keypress before continuing to print "Sing along!". The
problem can easily solved by replacing "getch();" with "Key = getch();"
But why does it work this time? And the even stranger thing is that if I
add a line feed i.e. "\n" at the end of the second output string, it
works correctly too. Can anyone shed some light?
- Raw text -