What is the easiest way to display changing numbers in the console? I have a normal command line program in C++ which uses cout
, but I'd like to display a percentage number representing the progress which counts up to 100 without printing a new line. How is that done? (If it matters: I'm on Windows 7)
When I’ve needed that I have just output a carriage return character, in C++ \r
.
Remember to flush the output each time, e.g.
cout << "\r" << x << "% completed. " << flush;
The spaces at the end to clear previous output on the line in case of Microsoft-like fluctuating progress.
Use the backspace character.
cout << "10%";
// ...
cout << "\b\b\b20%";
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