set::lower_bound

返回迭代器到中的第一个元素设置为等于或大于指定的键的键。

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

请参见

参考

set Class

set::lower_bound, set::upper_bound, 和 set::equal_range

标准模板库