C++: Re-use line printed to console

573 views Asked by At

Edit: Thanks to user mah's comment, I found what I was looking for. I want to rollback the line, see this question.


I always print information to the console using std::cout and std::endl, but when printing the progress of a loop this becomes quickly very crowded:

98.3968 % complete

98.5972 % complete

98.7976 % complete

98.998 % complete

99.1984 % complete

99.3988 % complete

99.5992 % complete

99.7996 % complete

The linux program wget for instance does this in a much nicer way, even constructing a progress bar consisting of equal (=) signs:Example output of wget

How can this or something similar be done in C++? Are there some nice libraries? I guess some terminal GUI libraries could do that, but I don't need the "user" part in "User Interface", I only want to print information in a better way.

1

There are 1 answers

0
Thomas Sparber On BEST ANSWER

You can either print the "="s without a line break or you can use ncurses which I think also wget uses.

But in my opinion ncurses is much work to do. For small Projects I recommend the simpler way.