Possible Duplicate:
How to delete printed characters from command line in C++
my question is, how do I change text while RUNNING a console window in C++. For example.
If I were to display this.
cout<<"0%";
cout<<"25%";
cout<<50%";
cout<<75%";
cout<<"100%";
It will make 5 different words. What if I want it to display 0% then 25% withought making a new word, I.E replacing the current 0% with a 25%. Is this even possible? Thanks in advance.
Use cout << number << '\r' << flush
.
The '\r'
means "carriage return" (go to beginning of line", the flush
means "make sure what I've just printed reaches the output now. Normally output is only printed when a end of line is provided.
Edit: If you have a situation where the length of the output varies, e.g. counting down, you will have to pad the output with sufficient spaces to cover any extra output. For example cout << setw(3) << number ...
or cout << number << " " ...
would work.
Be aware, however, if your line gets longer than the width of the termina/command windo, it may become messy.
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