返回解决的迭代器一个元素的第一个位置在具有键等效于指定的键的多个集的。
iterator find(
const Key& _Key
);
const_iterator find(
const Key& _Key
) const;
参数
- _Key
一个元素的排序关键字将匹配的键从要搜索的多个集的。
返回值
iterator 或 const_iterator 解析一个元素第一个位置一指定键的成功或最后一个元素的位置在多个集,则与未作为项中。
备注
成员函数返回解决在多个集的一个元素排序关键字与参数键是等效的二进制文件谓词该应用可比性关系生成基于的排序小于零的迭代器。
如果 find 的返回值赋给 const_iterator,不能修改多个对象集。如果 find 的返回值赋给 iterator,可以修改多个对象集。
示例
// multiset_find.cpp
// compile with: /EHsc
#include <set>
#include <iostream>
int main( )
{
using namespace std;
multiset <int> ms1;
multiset <int> :: const_iterator ms1_AcIter, ms1_RcIter;
ms1.insert( 10 );
ms1.insert( 20 );
ms1.insert( 20 );
ms1_RcIter = ms1.find( 20 );
cout << "The first element of multiset ms1 with a key of 20 is: "
<< *ms1_RcIter << "." << endl;
ms1_RcIter = ms1.find( 40 );
// If no match is found for the key, end( ) is returned
if ( ms1_RcIter == ms1.end( ) )
cout << "The multiset ms1 doesn't have an element "
<< "with a key of 40." << endl;
else
cout << "The element of multiset ms1 with a key of 40 is: "
<< *ms1_RcIter << "." << endl;
// The element at a specific ___location in the multiset can be
// found using a dereferenced iterator addressing the ___location
ms1_AcIter = ms1.end( );
ms1_AcIter--;
ms1_RcIter = ms1.find( *ms1_AcIter );
cout << "The first element of ms1 with a key matching" << endl
<< "that of the last element is: "
<< *ms1_RcIter << "." << endl;
// Note that the first element with a key equal to
// the key of the last element is not the last element
if ( ms1_RcIter == --ms1.end( ) )
cout << "This is the last element of multiset ms1."
<< endl;
else
cout << "This is not the last element of multiset ms1."
<< endl;
}
要求
标头: <set>
命名空间: std