代码:

#include <unistd.h>
#include <iostream>
#include <string>
#include <iomanip>
/*设置必备的头文件*/
using namespace std;

void print_process(string strName, float fValue, bool flag = false)
{
if(0>fValue || fValue>1)
{
cout << "进度参数必须大于0且小于1" << endl;
return;
}

fValue = fValue*100;

cout<<setiosflags(ios::fixed)<<setprecision(2);  //设置出书的小数后精度为2

string tag = "["+strName+"]"+"process:"+string((fValue/10), '*')+"[";
// flush擦除,\r定位到行首
cout << flush << '\r' << tag << fValue << "%]";
if(flag)
{
usleep(1000); //1000us
}
}

int main() {
for(int i = 0; i <=12345; i++) {
// flush擦除,\r定位到行首
float f = (float)i/12345.0;
print_process("mytest",f,true);
}
cout << endl;
cin.get();
return 0;
}

相关文章:

  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-24
  • 2021-06-14
  • 2021-12-31
猜你喜欢
  • 2021-06-18
  • 2021-11-08
  • 2021-10-10
  • 2021-06-11
  • 2021-12-27
  • 2022-12-23
相关资源
相似解决方案