From: Alain Magloire Message-Id: <199905092116.RAA26138@spock2.ECE.McGill.CA> Subject: Re: Quirky getch() (fwd) To: djgpp-workers AT delorie DOT com Date: Sun, 9 May 1999 17:16:08 -0400 (EDT) In-Reply-To: from "Eli Zaretskii" at May 9, 99 02:30:28 pm X-Mailer: ELM [version 2.4 PL25] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Reply-To: djgpp-workers AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk Bonjour > > The thought that every > > call to getch() would be preceded by automatic calls to fflush(stdout) > > and fflush(stderr) is chilling indeed. > > Why is it more chilling than what we already do? stderr is an unbuffered stream, you should not have to do fflush(stderr). But what is getch ? This is code is wrong : int main () { FILE * f = fopen (...); ... fwrite (..., f); write (fileno(f), ...); ... fwrite (..., f); write (fileno(f), ...); } This is incorrect meaning that the stream will intertwine. It is obvious that mixing two APIs, stdio and basic I/O will make the flow of data inconsistent, unless you fflush() between each call or use setvbuf()/setbuf() to unbuffered. And it's the same thing here : ... int main() { clrscr(); cout << "Hello World\n"; cout << "Sing along!"; getch(); return 0; } You're using two different APIs again, Iostreams and stdio(getch) or whatever API getch() is part of. If I do cout << "Hello World\n"; cout << Sing Aling !"; read (0, &c, 1); I don't think you'll modify read() to fflush(). I don't have my C++ std with me but the correct/portable approach should have been to, cout.flush() or to use endl or simply to use cin. cout and cin are tied in the lib. my 0.02$ canadian/Euro, is that you have many different APIs for I/O: stdio, iostream, basic I/O, getch. If you mix them you should be very carefull, each have they're own bufferring, or simply stick to one. -- alain