Skip to content

Instantly share code, notes, and snippets.

@Treebug842
Created November 30, 2021 10:33
Show Gist options
  • Save Treebug842/41952fecfb8006137da352ed888b121f to your computer and use it in GitHub Desktop.
Save Treebug842/41952fecfb8006137da352ed888b121f to your computer and use it in GitHub Desktop.
Simple Loading bar in c++
#define COUNTER_TIME_S 10
#define DELAY_MS 1000
#include <windows.h>
#include <iostream>
void clearScreen(int characterLength) {
for (int i=0; i<characterLength; i++) {
std::cout << "\b";
}
}
int main() {
for (int i=0; i<COUNTER_TIME_S; i++) {
std::cout << "[";
for (int j=0; j<i; j++) {std::cout << "#";}
for (int j=(COUNTER_TIME_S-i); j>0; j--) {std::cout << " ";}
std::cout << "]";
Sleep(DELAY_MS);
clearScreen(COUNTER_TIME_S+2);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment