"zl2k" <kd*******@gmail.comwrote:
I am trying to moniter the runing of a program by printing out some
characters in a line at each stage. say,
//program part1
cout<<"part1 ";
//program part2
cout<<part2 ";
...
I was expecting the program will pring "part1 part2 part3 part4 ...."
in realtime but instead it only print out when the program is finished.
I force it to print out by adding <<endl for each cout then the output
turns to vertical which is hard to see. My question is, how may I print
it in a line in realtime? Thanks.
As Victor Bazarov rightly pointed out, you can use flush at each point
where you want to force output, like so:
//program part1
cout << "part1 " << flush;
//program part2
cout << "part2 " << flush;
Another thing you can use is the "endl" manipulator, which first
prints an endline character ('\n'), then flushes the stream.
I tend to write text a line at a time in my progrms with immediate
output, like so:
//program part1
cout << "part1" << endl;
//program part2
cout << "part2" << endl;
which prints:
part1
part2
part3
etc.
in real-time.
I just thought I'd mention that option.
--
Cheers,
Robbie Hatley
East Tustin, CA, USA
lone wolf intj at pac bell dot net
(put "[usenet]" in subject to bypass spam filter)
http://home.pacbell.net/earnur/