Skip to content

Instantly share code, notes, and snippets.

@phrz
Created November 11, 2015 18:40
Show Gist options
  • Save phrz/a42907ec371a987bb5fb to your computer and use it in GitHub Desktop.
Save phrz/a42907ec371a987bb5fb to your computer and use it in GitHub Desktop.
I made a command line progress bar in C++ for funsies
#include <iostream>
#include <iomanip>
using namespace std;
int main(int argc, char *argv[]) {
int width = 15;
for(int p = 0; p <= 100; ++p) {
int full = (double)p/100*width;
cout << string(100,'\n');
cout << setw(3) << p;
cout << "% [";
for(int i = 0; i < full; ++i) cout << "█";
cout << string(width-full, ' ');
cout << "]" << string(8,'\n');
cout.flush();
usleep(500*1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment