C++ Program, Console/Terminal Output. How to implement "updating text" -
i writing c++ program, runs long data analysis algorithm. takes several days finish running, useful have prompt outputs "percentage complete" every time new loop in program starts user (me) knows computer isn't sitting in infinite loop somewhere or has crashed.
at moment doing basic way, computing percentage complete floating point number , doing:
std::cout << "percentage complete: " << percentage_complete << " %" << std::endl; but, when program has million loops run, kind of messy. in addition, if terminal scrollback 1000 lines, lose initial debug info printed out @ start once program 0.1 % complete.
i copy idea have seen in other programs, instead of writing new line each time percentage complete, replace last line written terminal new percentage complete.
how can this? possible? , if so, can done in cross platform way? there several methods of doing this?
i unsure how describe trying clearly, hope clear enough understand trying do.
to clarify, rather seeing this:
running program. debug info: total number of loops: 1000000 percentage complete: 0 % percentage complete: 0.001 % percentage complete: 0.002 % . . . percentage complete: 1.835 % i see this:
running program. debug info: total number of loops: 1000000 percentage complete: 1.835 % and on next loop terminal should update this:
running program. debug info: total number of loops: 1000000 percentage complete: 1.836 % i hope that's enough information.
(okay, output 100000 steps, not 1000000.)
instead of \n or std::endl, use \r. difference latter returns cursor beginning if line without new line.
disclaimer (as per lightness' objections): not portable, ymmv.
Comments
Post a Comment