multiset::upper_bound

返回迭代器在多集的第一个元素与大于指定的键大的密钥。

const_iterator upper_bound( 
   const Key& _Key 
) const; 
iterator upper_bound( 
   const Key& _Key 
);

参数

  • _Key
    参数用键元素的排序关键字进行比较从搜索的多级集的。

返回值

解决一元素位置在多键集与参数比键的 迭代器const_iterator 大于最后一个元素成功或解决的位置在多集,如果与对于找到键。

示例

// multiset_upper_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.upper_bound( 20 );
   cout << "The first element of multiset ms1 with a key greater "
           << "than 20 is: " << *ms1_RcIter << "." << endl;

   ms1_RcIter = ms1.upper_bound( 30 );

   // 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 greater than 30." << endl;
   else
      cout << "The element of multiset ms1 with a key > 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.begin( );
   ms1_RcIter = ms1.upper_bound( *ms1_AcIter );
   cout << "The first element of ms1 with a key greater than"
        << endl << "that of the initial element of ms1 is: "
        << *ms1_RcIter << "." << endl;
}
  

要求

标头: <set>

命名空间: std

请参见

参考

multiset 类

标准模板库