Posted on 2011-01-10 19:20
逐渐 阅读(538)
评论(0) 编辑 收藏 引用
boost progress包括progress_timer, progress_display,分别用于输出程序运行的时间和显示运行进度.
1
2 #include <boost/progress.hpp>
3
4 #include <iostream>
5 #include <vector>
6
7 using std::cout;
8 using std::endl;
9 using std::vector;
10 using boost::progress_display;
11 using boost::progress_timer;
12
13 int main()
14 {
15 vector<int> v;
16 int i;
17 for(i=0; i<10; i++)
18 v.push_back(i);
19
20 progress_display display(v.size());
21
22 vector<int>::iterator it;
23 progress_timer elapsed;
24 for(it=v.begin(); it!=v.end(); ++it)
25 {
26 //do something
27 ++display;
28 }
29
30 cout<<"elapsed time: ";
31 return 0;
32 }
程序运行结果截图:
说明:progress_display重载了operator++,progress_timer在定义时开始计时,对象析构时输出所耗时间.