status während laufzeit ausgeben (konsole)
-
hallo, folgendes habe ich mir ausgedacht. funktioniert auch super, wollte nur mal fragen, ob jemand eine etwas elegantere lösung kennt?
es handelt sich um den berühmten, sich auf der stelle drehenden slash.#include <iostream> using namespace std; int main() { int progress = 0; cout << "progressing "; for(int i = 0; i < 100000; i++) { if(progress == 0) { cout << "\b" << "-" << flush; progress++; } else if(progress == 1) { cout << "\b" << "/" << flush; progress++; } else if(progress == 2) { cout << "\b" << "|" << flush; progress++; } else if(progress == 3) { cout << "\b" << "\\" << flush; progress = 0; } } cout << "\b" << "finished." << flush << endl; return 0; }danke und gruß, der chris
-
Hallo
Was man auf jeden Fall verwenden kann ist:
switchchrische
-
progress = (progress + 1) % 4
//edit
char zeichen[] = "-/|\\"; ... cout << zeichen[progress]; progress = (progress + 1) % 4;
-
wunderbar, das mit dem modulo gefällt mir sehr gut, tolle idee.. vielen dank!
besten gruß, chris
-
kommt aufs gleiche raus, ist aber kürzer.
cout << "\b" << zeichen[(progress++) % 4] << flush;