Skip to content

Instantly share code, notes, and snippets.

@morris821028
Created March 5, 2017 14:19
Show Gist options
  • Save morris821028/46d39997eb58bc1f24c06d75a8ab6310 to your computer and use it in GitHub Desktop.
Save morris821028/46d39997eb58bc1f24c06d75a8ab6310 to your computer and use it in GitHub Desktop.
processbar.cpp
#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