Mail Archives: djgpp/1999/05/08/14:40:18
From: | Chong Kai Xiong <w_velocity AT yahoo DOT com>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Quirky getch()
|
Date: | Thu, 06 May 1999 00:01:42 +0800
|
Organization: | Singapore Telecommunications Ltd
|
Lines: | 27
|
Message-ID: | <37306B66.BFCC4CDD@yahoo.com>
|
NNTP-Posting-Host: | as002352.singnet.com.sg
|
Mime-Version: | 1.0
|
X-Mailer: | Mozilla 4.04 [en] (Win95; I)
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
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 -