STL的find,find_if函数提供了一种对数组、STL容器进行查找的方法。使用该函数,需添加
#include <algorithm>
我们查找一个vector中的数据,通常用std::find(),例如:
运行结果:
来个稍复杂点的例子,其他的可以类推,实现功能如下:
产品、账号多对多的关系,通过产品找到对应的账号列表。
运行结果:

上例中用到了find_if函数,并自己指定predicate function(即find_if函数的第三个参数,请查阅STL手册)。
find_if函数的定义:template<class InputIterator, class Predicate>
InputIterator find_if(InputIterator _First, InputIterator _Last, Predicate _Pred);
Parameters
_First
An input iterator addressing the position of the first element in the range
to be searched.
_Last
An input iterator addressing the position one past the final element in the
range to be searched.
_Pred
User-defined predicate function object that defines the condition to be
satisfied by the element being searched for. A predicate takes single argument
and returns true or false.