Mail Archives: djgpp-workers/1999/05/09/17:21:26
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
- Raw text -