Created
March 5, 2017 14:19
-
-
Save morris821028/46d39997eb58bc1f24c06d75a8ab6310 to your computer and use it in GitHub Desktop.
processbar.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#ifdef _WIN64 | |
#include <windows.h> | |
#else | |
#include <unistd.h> | |
#endif | |
using namespace std; | |
void do_timecomsuming_work() { | |
#ifdef _WIN64 | |
Sleep(100); | |
#else | |
usleep(100000); | |
#endif | |
} | |
int main() { | |
for (int i = 0; i <= 100; i++) { | |
char bar[105]; | |
int barClen = 70; | |
bar[0] = '[', bar[barClen+1] = ']', bar[barClen+2] = '\0'; | |
for (int j = 1; j <= barClen; j++) { | |
if (j < i*barClen/100) | |
bar[j] = '='; | |
else if (j == i*barClen/100) | |
bar[j] = '>'; | |
else | |
bar[j] = ' '; | |
} | |
printf("\r%s%4d%%", bar, i); | |
fflush(stdout); | |
do_timecomsuming_work(); | |
} | |
printf("\ndone.\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment