// for_each.cpp -- 2011-10-01-22.31
#include "stdafx.h"
#include <iostream>
#include <algorithm>
#include <vector>
using std ::vector ;
template<class T>
class Print
{
public:
void operator () (const T & t) const
{
std ::cout << t << " " ;
}
} ;
int _tmain(int argc, _TCHAR* argv[])
{
int arr1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9} ;
vector<int> vec1(arr1, arr1 + sizeof arr1 / sizeof (int)) ;
// for_each (beg, end, f) ;
// 操作前:[beg,end)标示输入序列.f是一元函数对象.
// 操作后:f操作符依次作用于输入序列中的每个元素.忽略f操作符的返回值.
// 返回值:无.
// 备注: 无.
for_each(vec1.begin(), vec1.end(), Print<int> ()) ;
std ::cin.get() ;
return 0 ;
}
for_each
最新推荐文章于 2025-05-08 19:55:25 发布
1665

被折叠的 条评论
为什么被折叠?



