Date: Sun, 9 May 1999 12:15:54 +0300 (IDT) From: Eli Zaretskii X-Sender: eliz AT is To: djgpp-workers AT delorie DOT com cc: DJ Delorie Subject: Quirky getch() (fwd) Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp-workers AT delorie DOT com 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 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 #include 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?