set::lower_bound
傳回 Iterator 置於集合的第一個項目具有等於或大於指定之索引鍵的索引鍵。
const_iterator lower_bound(
const Key& _Key
) const;
iterator lower_bound(
const Key& _Key
);
參數
- _Key
引數索引鍵與項目的排序鍵會比較搜尋的集合中。
傳回值
處理一個項目位置集合中的索引鍵是等於或大於金鑰的引數或解決成功最後一個項目的位置。這個集合的列舉值則為 const_iterator ,如果遊戲不為索引鍵中找到。
範例
// set_lower_bound.cpp
// compile with: /EHsc
#include <set>
#include <iostream>
int main( )
{
using namespace std;
set <int> s1;
set <int> :: const_iterator s1_AcIter, s1_RcIter;
s1.insert( 10 );
s1.insert( 20 );
s1.insert( 30 );
s1_RcIter = s1.lower_bound( 20 );
cout << "The element of set s1 with a key of 20 is: "
<< *s1_RcIter << "." << endl;
s1_RcIter = s1.lower_bound( 40 );
// If no match is found for the key, end( ) is returned
if ( s1_RcIter == s1.end( ) )
cout << "The set s1 doesn't have an element "
<< "with a key of 40." << endl;
else
cout << "The element of set s1 with a key of 40 is: "
<< *s1_RcIter << "." << endl;
// The element at a specific location in the set can be found
// by using a dereferenced iterator that addresses the location
s1_AcIter = s1.end( );
s1_AcIter--;
s1_RcIter = s1.lower_bound( *s1_AcIter );
cout << "The element of s1 with a key matching "
<< "that of the last element is: "
<< *s1_RcIter << "." << endl;
}
需求
標頭: <set>
命名空間: std