赞
踩
函数原型:for_each(iterator beg, iterator end, _func);
其中: beg— 开始迭代器
end— 结束迭代器
_func— 函数或者函数对象
示例:
#include <algorithm> #include <vector> //普通函数 void print01(int val) { cout << val << " "; } //函数对象 class print02 { public: void operator()(int val) { cout << val << " "; } }; //for_each算法基本用法 void test01() { vector<int> v; for (int i = 0; i < 10; i++) { v.push_back(i); } //遍历算法 for_each(v.begin(), v.end(), print01); cout << endl; for_each(v.begin(), v.end()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。