Ok, I am a bit embarrassed to ask such a simple thing but still.
I have command line utility application and need to show progress to the user.
I could write progress into cout, like this:
std::cout << "10%\n";
...
std::cout << "20%\n";
...
std::cout << "30%\n";
… but as a result user will see:
some line printed before
10%
20%
30%
...
… but what i really need is that percentage got updated, like this at the beginning:
some line printed before
10%
...
… and after update:
some line printed before
20%
...
… and after second update:
some line printed before
30%
...
How should I achieve that?
Instead of using
'\n', use'\r':Print newline (
'\n') when done.It’s important to use
std::flushso the stream contents really is output.