1.代码
////// 更新进度条 /// /// 进度(0-1) void showProgress(float progress) { if (progress > 1) { progress = 1; } int pa = progress * 50; std::cout << "33[1A"; // 终端光标向上移动一行 std::cout << "[" + std::string(pa, '=') + ">" + std::string(50 - pa, ' ') << "] " << progress * 100 << "%" << std::endl; fflush(stdout); // 刷新缓冲区 }
2.测试
int main()
{
for (int i = 1; i < 101; i++)
{
float progress = i * 1.0 / 100;
showProgress(progress);
}
return 0;
}
3.效果
[==================================================>] 100%



