找到元素的第一次出现的位置具有指定值的大小。
template<class InputIterator, class Type>
InputIterator find(
InputIterator _First,
InputIterator _Last,
const Type& _Val
);
参数
_First
解决输入的迭代器第一个元素的位置在指定要搜索的范围。_Last
解决输入的迭代器通过最终元素的位置一个位于指定要搜索的范围。_Val
值将搜索。
返回值
解决输入的迭代器指定值的第一次出现在搜索的大小。如果该值不存在该范围,则返回的迭代器解决该范围的最后位置,则通过最终元素。
备注
用于的 operator== 确定在元素和指定值之间的匹配必须实施在其操作数之间的等效性关系。
示例
// alg_find.cpp
// compile with: /EHsc
#include <list>
#include <algorithm>
#include <iostream>
int main() {
using namespace std;
list <int> L;
list <int>::iterator Iter;
list <int>::iterator result;
L.push_back( 40 );
L.push_back( 20 );
L.push_back( 10 );
L.push_back( 30 );
L.push_back( 10 );
cout << "L = ( " ;
for ( Iter = L.begin( ) ; Iter != L.end( ) ; Iter++ )
cout << *Iter << " ";
cout << ")" << endl;
result = find( L.begin( ), L.end( ), 10 );
if ( result == L.end( ) )
cout << "There is no 10 in list L.";
else {
cout << "There is a 10 in list L";
if ( ++result != L.end() )
cout << " and it is followed by a " << *result << ".";
}
cout << endl;
}
Output
L = ( 40 20 10 30 10 )
There is a 10 in list L and it is followed by a 30.
要求
标头: <algorithm>
命名空间: std