multiset::lower_bound
傳回Iterator至多重集的第一個項目具有等於或大於指定的索引鍵。
const_iterator lower_bound(
const Key& _Key
) const;
iterator lower_bound(
const Key& _Key
);
參數
- _Key
引數的索引鍵使用一個項目來排序鍵比較從多重集 (Multiset) 的搜尋。
傳回值
處理一個項目位置在多重集(Multiset)的具有索引鍵等於或大於引數金鑰,或是處理成功最後一個項目的位置在多重集(Multiset)的 iterator 或 const_iterator ,如果符合沒有索引鍵中找到。
範例
// multiset_lower_bound.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( 30 );
ms1_RcIter = ms1.lower_bound( 20 );
cout << "The element of multiset ms1 with a key of 20 is: "
<< *ms1_RcIter << "." << endl;
ms1_RcIter = ms1.lower_bound( 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 derefenced iterator addressing the location
ms1_AcIter = ms1.end( );
ms1_AcIter--;
ms1_RcIter = ms1.lower_bound( *ms1_AcIter );
cout << "The element of ms1 with a key matching "
<< "that of the last element is: "
<< *ms1_RcIter << "." << endl;
}
需求
標題: <set>
命名空間: std