孤独的猫

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

类属算法for_each的功能是对序列中的每个元素施加由函数f指定的操作。

1 // Illustrating the generic for_each algorithm
2 #include <iostream>
3 #include <cassert>
4 #include <algorithm>
5 #include <string>
6 #include <list>
7 #include <iostream>
8 using namespace std;
9
10 void print_list(string s)
11 {
12 cout << s << endl;
13 }
14
15 int main()
16 {
17 cout << "Illustrating the generic for_each algorithm."
18 << endl;
19 list<string> dlist;
20 dlist.insert(dlist.end(), "Clark");
21 dlist.insert(dlist.end(), "Rindt");
22 dlist.insert(dlist.end(), "Senna");
23
24 // Print out each list element:
25 for_each(dlist.begin(), dlist.end(), print_list);
26 return 0;
27 }

posted on 2011-06-01 21:35  孤独的猫  阅读(2154)  评论(0编辑  收藏  举报