How to display a progress indicator in pure C/C++ (cout/printf)?

后端 未结 8 1385
夕颜
夕颜 2020-12-12 11:10

I\'m writing a console program in C++ to download a large file. I have known the file size, and I start a work thread to download. I want to show a progress indicator to mak

8条回答
  •  青春惊慌失措
    2020-12-12 11:36

    Another way could be showing the "Dots" or any character you want .The below code will print progress indicator [sort of loading...]as dots every after 1 sec.

    PS : I am using sleep here. Think twice if performance is concern.

    #include
    using namespace std;
    int main()
    {
        int count = 0;
        cout << "Will load in 10 Sec " << endl << "Loading ";
        for(count;count < 10; ++count){
            cout << ". " ;
            fflush(stdout);
            sleep(1);
        }
        cout << endl << "Done" <

提交回复
热议问题