示例代码:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
//是否大于5
bool greater5(int n)
{
return n > 5;
}
//by zhaocl
int main()
{
vector<int> vi;
vi.push_back(3);
vi.push_back(6);
vi.push_back(9);
//返回第一个大于5的元素地址
vector<int>::iterator it = find_if(vi.begin(),vi.end(),greater5);
cout<<"the first greater number than 5 is "<< *it <<endl;
system("pause");
return 0;
}
说明:
在这里greater5只是一个函数的对象,然后作为find_if的一个参数。