Possible Duplicate:
How to update a printed message in terminal without reprinting (Linux)
I have c++ code, performing some simulations.
I want to show the percentage of my simulation, but I don't want to output a new line every step, like
%1
%2
%3
...
Is there a way, in c++ or in shell scripts to show the progress without creating new lines?
Thanks
Anyone know how to update a number on my personal webpage without refreshing the whole page?
Thanks
double N=0;
forAll (internalIDs_, i) {
N++;
double percent = 100*N/internalIDs_.size();
// Info<< "\rProgress: " << percent << "%" << endl;
printf("\r[%6.4f%%]",percent);}
The terminal cursor keeps blinking cyclically through the numbers, very annoything, how to get rid of this?
The trick used for this is to return to the first position in the current line instead of progressing to the next line.
This is done by writing the \r
character (carriage return) to the terminal/stdout.
cout << "\r%1";
cout << "\r%2";
cout << "\r%3";
...
\r - move at the begin of line;
but! if :
cout << "\rsomelongmessage";
cout << "\rshort";
then you get at out:
shortongmessage
because of:
somelongmessage
^^^^^
short
but you can:
cout << "\rsomelongmessage";
cout << "\rshort ";
then you get finally:
short
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With