-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogress-bar.h
More file actions
27 lines (23 loc) · 775 Bytes
/
Copy pathprogress-bar.h
File metadata and controls
27 lines (23 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <chrono>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <thread>
void show_progress_bar_v2(std::ostream& os, std::string message,
float percentage, char symbol = '#', int delay = 0)
{
static const auto bar_length = 50;
int progress_level = static_cast<int>(percentage/100*bar_length);
if (percentage <=0)
os << message << '\n';
message.clear();
message += std::string(progress_level, symbol);
os << "\r["
<< message << std::string(bar_length - progress_level, ' ') << "] "
<< std::setw(3) << static_cast<int>(percentage) << "%"
<< std::flush;
std::this_thread::sleep_for(std::chrono::milliseconds(delay));
if (percentage >= 100)
os << "\n";
}