The implementation of progress bar in C++style

The implementation of progress bar in C++style,第1张

The performance (the insights)

progress_bar

The corresponding codes
#include 
#include 
typedef long long int TYPE_INDEX;

void progress_bar(TYPE_INDEX current, TYPE_INDEX total, std::string name){
	if (current < total - 1){
		std::cout << "\r " << name << " progress: [" << current * 100 / (total - 1) << "%]";
	} else {
		std::cout << "\r " << name << " progress completed: [100%]";
	}
	TYPE_INDEX show_num = current * 20 / total;
	for (TYPE_INDEX i = 0; i < show_num; i++){
		std::cout << "█";
	}
}
int main()
{
    TYPE_INDEX total{100000};
    for (TYPE_INDEX i = 0; i < total; i++)
    {
        progress_bar(i, total, "test");
    }
    std::cout << std::endl;
    return 0;
}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/797763.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-06
下一篇2022-05-06

发表评论

登录后才能评论

评论列表(0条)

    保存