Introduction
It is just a part of the code, and it is not an application. But it can be compile and run directly to show how it is work and what it is display. So you may need to make lots of edit what you need to make it work carefully.
The code is using a new feature about C++ 11 —threadto be supported the multithreading of programing. So you cannot compile the code on the old compiler. It may bring some code error. Please upgrade the new compile or install the latest version of Visual Studio. ( I am using the Visual Studio 2017 Release. )
About the first version
The first version was not supported the multithreading of programing, but the left side of the clock once again need to wait for a new request (the request is the same to the progress bar), so the user experience is really really bad.
I think the first version of it is meaningless, so I put the second edition directly.
Development environment
We need the latest version of Visual Studio 2017. But you can use all of the compiler which can be supported the specification of C ++ 11 can be used normally. The code used theWindows.hof the header file. So you need to run on the Microsoft Windows environment.
Show the result
Code
#include <iostream> #include <Windows.h> #include <thread> using namespace std; void clock(int cache); void run_clock(int y); void run_line(int y); int load_num = 0; int x = 6; int main() { int local;//Save the local of the output(The entire progress bar is output on the local line) int i; cin >> local; thread clock(run_clock, local); clock.detach(); i = 0; while (i!=50)//Create a preload bar { cout << "▂"; i++; } run_line(local); cout << endl << "Done!" << endl; system("pause"); return 0; } void gotoxy(int x, int y)//The function of the function, jump cursor see https://www.geekdt.com/248.html { COORD pos; pos.X = x; pos.Y = y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos); } void run_line(int y)//Draw the progress bar { while (load_num != 100) { gotoxy(x, y); cout << "█"; x += 2; load_num += 2; gotoxy(x, y); printf("<%d%%>", load_num);//Output progress percentage Sleep(500); } } void run_clock(int y)//Draw the model "clock { int i = 1; while (load_num!=100) { if (i > 4) { i = 1; } gotoxy(3, y); clock(i); i++; gotoxy(x+4, y); Sleep(200); } } void clock(int cache)//Create the model "clock" { switch (cache) { case 1: { cout << "|"; break; } case 2: { cout << "/"; break; } case 3: { cout << "-"; break; } case 4: { cout << "\\"; break; } } }
Download the code
Because of the html tag, some code parts of the code may be displayed some wrong we cannot know in different browser. Such as miss some parts of the code, displayed the wrong things, garbled and so on. I hope you can help me to fix these problems. So, if you need to use this code. Please download the cpp file to edit, to prevent unnecessary trouble.
[download]https://files.geekdt.com/index.php?share/file&user=1&sid=7ujZUkbR[/download]