pantonante
7/20/2018 - 3:06 PM

Progress Indicator

template <class T>
int numDigits(T number)
{
    int digits = 0;
    if (number < 0) digits = 1; // remove this line if '-' counts as a digit
    while (number) {
        number /= 10;
        digits++;
    }
    return digits;
}

std::cout << "\rProgress: " << std::setw(numDigits(counter)) << std::setfill(' ') << counter
              << " (" << std::setw(6) << std::setfill(' ') << std::fixed << std::setprecision(2)
              << static_cast<float>(counter) / static_cast<float>(max_counter) * 100.0f << "%)"
              << std::flush;