progress_timer计时器继承自timer,具有timer的全部能力。除此之外,它会在析构时自动输出时间,省去了timer调用elapsed()的工作。
#include "stdafx.h"
#include <boost/progress.hpp>
int main()
{
boost::progress_timer t; //声明对象开始计时
int i = 10000000000; //操作
while (i--);
return 0;
} //退出作用域,调用析构函数,输出流逝的时间
输出结果是:
把progress_timer的输出转移到了stringstream中,它可以被转换为字符串供其他应用使用
#include <boost/progress.hpp>
#include <sstream>
int main()
{
std::stringstream str;
{
boost::progress_timer t; //声明对象开始计时
int i = 10000000000; //操作
while (i--);
return 0;
} //退出作用域,调用析构函数,输出流逝的时间
std::string temp = str.str();
std::cout << temp << std::endl;
}
输出结果是: