C++ Console Progress Indicator

后端 未结 4 662
一生所求
一生所求 2021-02-08 23:13

What would be an easy way of implementing a console-based progress indicator for a task that\'s being executed, but I can\'t anticipate how much time it would take?

I us

4条回答
  •  闹比i
    闹比i (楼主)
    2021-02-08 23:46

    Wow, clipper, perhaps you are talking about the @row,col things built in to the language? (Rhetorical question only...)

    You can do simple progress bars with printf: you can leave out the trailing newline. You can obviously begin or end the string with \b in order to overprint characters. It's easy to do the traditional -\|/ kind that way.

    I recall that the Eclipse UI guidelines recommended progress indicators regardless of how much you were able to tell about the actual progress. I think theory was that anything is better than nothing and to just do the best you can.

    The only trick that you are likely to need is potentially to defeat line buffering. Be sure to fflush(stdout) after each output operation. (Or ostream::flush())

提交回复
热议问题