// find_if.cpp -- 2011-10-02-22.05
#include "stdafx.h"
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
using std ::vector ;
using std ::equal_to ;
int _tmain(int argc, _TCHAR* argv[])
{
int arr1[] = {1, 2, 3, 4, 5, 3, 8, 9} ;
vector<int> vec1(arr1, arr1 + sizeof arr1 / sizeof (int)) ;
// find_if (beg, end, unaryPred) ;
// 操作前:[beg,end)标示输入序列.unaryPred操作符是一元函数对象.
// 操作后:确定输入序列中是否存在使unaryPred返回true的元素.
// 返回值:如果存在使unaryPred返回true的元素,返回指向第一个该元素位置的迭代器.
// 否则返回end.
// 备注: 如果使用二元函数对象,需使用绑定器将其转换为一元函数对象使用.
vector<int> ::iterator iter = find_if(vec1.begin(), vec1.end(), bind2nd(equal_to<int> (), 3)) ;
if (iter != vec1.end())
std ::cout << *iter << std ::endl ;
std ::cin.get() ;
return 0 ;
}
find_if
最新推荐文章于 2023-03-20 19:38:56 发布
1243

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



