zoukankan      html  css  js  c++  java
  • 【c++】打印进度条,Linux下进度条输出

    代码:

    #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擦除, 定位到行首
    cout << flush << ' ' << tag << fValue << "%]";
    if(flag)
    {
    usleep(1000); //1000us
    }
    }

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

  • 相关阅读:
    STL容器[26]
    SHELL[01]
    SHELL[04]
    SHELL[02]I/O重定向
    STL容器[39]
    stl.set用法总结
    STL容器[33]
    STL容器[29]
    hdu acm1071
    hdu acm 2673
  • 原文地址:https://www.cnblogs.com/cy1993/p/11570642.html
Copyright © 2011-2022 走看看