Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > how to print on screen in realtime

Reply
Thread Tools

how to print on screen in realtime

 
 
zl2k
Guest
Posts: n/a
 
      07-13-2006
hi, all
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.

zl2k

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      07-13-2006
zl2k wrote:
> hi, all
> 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.


Read about 'flush' manipulator. If it doesn't work, use your platform's
capabilities instead.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
 
Adi
Guest
Posts: n/a
 
      07-13-2006
cout << flush;
cout.flush();
cout << endl;

This will flush the buffered output to be printed. The output is
buffered and will be printed when it reaches a limit or when the
program ends or some other condition like that.

Adi

zl2k wrote:
> hi, all
> 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.
>
> zl2k


 
Reply With Quote
 
Marcus Kwok
Guest
Posts: n/a
 
      07-13-2006
zl2k <(E-Mail Removed)> wrote:
> 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.


I don't know about "realtime", but you can try adding std::flush instead
of std::endl.

// program part1
cout << "part1 " << flush;
// program part2
cout << "part2 " << flush;

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
 
Reply With Quote
 
Robbie Hatley
Guest
Posts: n/a
 
      07-14-2006
"zl2k" <(E-Mail Removed)> wrote:

> 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/


 
Reply With Quote
 
Marcus Kwok
Guest
Posts: n/a
 
      07-14-2006
Robbie Hatley <(E-Mail Removed)> wrote:
> "zl2k" <(E-Mail Removed)> wrote:
>> I force it to print out by adding <<endl for each cout then the output
>> turns to vertical which is hard to see.

>
> 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.


The OP had already considered that option but found the output to be too
hard to see.

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
print a vs print '%s' % a vs print '%f' a David Cournapeau Python 0 12-30-2008 03:19 AM
Problem - I want to print Current Output of Pdf file and should print once.I get print dialog box but it is not working keto Java 0 05-30-2007 11:27 AM
Lock Print Screen and File Print Bryan Shaw ASP .Net 3 04-20-2005 02:54 PM
Unlarging the print to print using PDF file to print Bun Mui Computer Support 3 09-13-2004 03:15 AM



Advertisments