Home    Publications    Links    Resources
Note: No claim or guarantee is intended.
Read, understand, learn, and use on your own responsibility.

Progress Meter

Here I demonstrate a simple and useful example for printing a progress meter that displays the computation progress of a C++ program in command-line. This is specially of value for time-consuming simulations in which a certain task is performed inside a loop.

Instead of looking at the non-responsive command-line for minutes and wildly guessing how much remains until the simulation finishes, you can actually watch the progress!

Ok. Let's dive right into it. Here is what the code looks like:
#include<iostream> //For cout
using namespace std;

int main() {
     float length = 1000;
     for (int i = 0; i < length; i++) {
          //This is the main function that
          //gets processed in each iteration.
          //Put your own code instead of this.
          //This prints the progress meter
          <<"% "

     //Display the results here.
     //Put your own code instead of this.
     return 0;

The above code is converted to html and syntax-highlighted by Code2HTML, v. 0.9.1 in Ubuntu.