progress_timer和progress_display

progress_timer.cpp 
#include <iostream>
#include <boost/progress.hpp>
#include <boost/static_assert.hpp>
#include <vector>
using namespace boost;
using namespace std;
template<int N=2>
class new_progress_timer:public progress_timer
{
public:
	new_progress_timer(std::ostream &os = std::cout):m_os(os)
	{
		BOOST_STATIC_ASSERT(N >= 0 && N <= 10);
	}
	~new_progress_timer()
	{
		try
		{
			std::istream::fmtflags old_flags = m_os.setf(std::istream::fixed,std::istream::floatfield);
			std::streamsize old_prec = m_os.precision(N);
			m_os << elapsed() << "s \n"
				 << std::endl;
			m_os.flags( old_flags);
			m_os.precision(old_prec);
		}
		catch(...){}
	}
private:
	std::ostream &m_os;
};
template<>
class new_progress_timer<2>:public boost::progress_timer{};
int main()
{
	new_progress_timer<10> t;
	//system("pause");
}

progress_display.cpp

 

#include <iostream>
#include <string>
#include <boost/progress.hpp>
#include <boost/static_assert.hpp>
#include <vector>
using namespace boost;
using namespace std;

int main()
{
	vector<string> v(1000000);
	progress_display pd(v.size(),cout,"hello","ajioy"," prog");
	vector<string>::iterator pos;
	for(pos = v.begin(); pos != v.end(); ++pos)
	{
		  *pos = 'a';
			++pd;
	}
	//system("pause");
}


运行结果:

hello0%   10   20   30   40   50   60   70   80   90   100%
ajioy|----|----|----|----|----|----|----|----|----|----|
 prog***************************************************

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值