Posted on 2011-01-10 19:20
逐漸 閱讀(556)
評論(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在定義時開始計時,對象析構時輸出所耗時間.