Here is a simple program designed to keep track of loop progress and print it at certain stages (every 10% in this example).
using namespace std;
int main() {
double step = 0.1;
double last_progress = 0;
int num_iter = 100;
for (int i = 1; i <= num_iter; ++i) {
double k = i * 1.0 / num_iter;
if (k > last_progress + step) {
last_progress += step;
printf("\r%7.2f%%", last_progress * 100);
fflush(stdout);
this_thread::sleep_for(chrono::milliseconds(10));
}
}
return 0;
}
I expect the output to have a single overridable line showing the current progress. If I launch this program in a console everything works as expected. However, when I try to execute it in CLion (2017.1.1) I get the following output:
10.00% 20.00% 30.00% 40.00% 50.00% 60.00% 70.00% 80.00% 90.00% 100.00%
I've read this thread and I tried disabling putty but it didn't help. This problem has something to do with time in between prints for when I remove the sleep line everything works fine.