www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1999/05/09/05:18:16

Date: Sun, 9 May 1999 12:15:54 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: djgpp-workers AT delorie DOT com
cc: DJ Delorie <dj AT delorie DOT com>
Subject: Quirky getch() (fwd)
Message-ID: <Pine.SUN.3.91.990509121440.3278V-100000@is>
MIME-Version: 1.0
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 <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 -


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