Console Progress Bar library: A C++ library for printing the progress of numeric iterations on the console
void print(const unsigned int ¤t_position, const unsigned int &max_position)
void print_full()
void print_empty()
double get_current_percentage()
void erase()
The implementation of the progress bar has a default style of the type Progress: [======= ] 70.00%.
The default style may be changed as desired through the functions listed below.
void set_bar_size(unsigned int bar_size)
void set_bar_delimiters(std::string left_delimiter_char, std::string right_delimiter_char)
void set_bar_fillers(std::string filler_char, std::string blanker_char)
Notice that although filler_char, blanker_char, left_delimiter_char and right_delimiter_char are declared as std::string, each one must be a single character that occupies a single space on the console, otherwise they will be restored to the default style. In particular, left_delimiter_char and right_delimiter_char may be an empty string ("").
Additionally, the value of bar_size should be chosen such that the total size of the progress bar does not exceed the width of the console.
The library is in a header-only library style, i.e., there is nothing to build, you only have to include the console-progress-bar-library.hpp file into your project.
#include <iostream>
#include <unistd.h> // Required for 'sleep()'
#include "console-progress-bar-library.hpp"
int main()
{
// Creating the object my_progress
console_progress_bar my_progress;
// Styling the progress bar
my_progress.set_bar_size(10);
my_progress.set_bar_fillers("█", "░");
my_progress.set_bar_delimiters("", "");
// Required for printing Unicode chars such as █ and ░ on Windows cmd
system("chcp 65001 > nul");
// Printing a progress of 0%
my_progress.print_empty();
// Loop for printing the progress after each iteration
for (int i=0; i<=98; i++)
{
sleep(1); // Waiting one second, simulating a slow process
my_progress.print(i,17); // Printing the progress
}
// Printing a progress of 100%
my_progress.print_full();
// Erasing the progress bar out of the console
my_progress.erase();
}
█, ░, ⚫, ⚪, ■, ▰, ▱, ...
The codes and routines were developed and are updated by Jhonas O. de Sarro (@jodesarro).
This project is protected under MIT License.

