终端显示进度条

终端显示进度条

等于号

void
printProgress(unsigned current, unsigned total, const string& tip = "Progress") {
  float percent = total == 0 ? 100.0f : (current * 100.0f / total);
  int bars = static_cast<int>(percent / 2); // 50 格进度条
  std::string bar(bars, '=');

  printf("\r%s [%-50s] %3.0f%%", tip.c_str(), bar.c_str(), percent);
  fflush(stdout);
}

百分比

void printProgress(unsigned current, unsigned total, const std::string& tip = "Progress") {
  float percent = total == 0 ? 100.0f : (current * 100.0f / total);
  printf("\r%s: %6.2f%%", tip.c_str(), percent);
  fflush(stdout);
}
posted @ 2025-07-14 10:25  卑以自牧lq  阅读(12)  评论(0)    收藏  举报