C++ changing output on console

后端 未结 3 626
温柔的废话
温柔的废话 2021-02-02 16:14

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 percenta

3条回答
  •  死守一世寂寞
    2021-02-02 16:39

    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.

    enter image description here

提交回复
热议问题