Created
May 10, 2013 04:35
-
-
Save lbl1985/5552400 to your computer and use it in GitHub Desktop.
During processing a bunk of computation, people always eager to know how far from finish. The progress bar is exactly design for it. Console program does not support those fancy GUI, therefore something like below might be preferred. [======> ] 37%
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void DrawProgressBar(int len, double percent){ | |
std::string progress; | |
bool firstSpace = true; | |
for (int i = 0; i < len; ++i) { | |
if (i < static_cast<int>(len * percent)) { | |
progress += "="; | |
} else { | |
if (firstSpace) | |
{ | |
progress += ">"; | |
firstSpace = false; | |
} | |
progress += " "; | |
} | |
} | |
std::printf("[%s] %d %% \r", progress.c_str(), static_cast<int>(100*percent)); | |
std::flush(std::cout); // Required. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment