次の方法で共有


set::upper_bound

指定したキー、キーと文字セットの最初の要素への反復子を返します。

const_iterator upper_bound(
   const Key& _Key
) const;

iterator upper_bound(
   const Key& _Key
);

パラメーター

  • _Key
    検索する要素のセットの並べ替えキーと比較される引数のキー。

戻り値

引数のキー [反復子] より大きいか const_iterator 一致するキーにあるセットに最後の要素の次の場所を示すキーと設定の要素の位置をアドレス、または。

使用例

// set_upper_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.upper_bound( 20 );
   cout << "The first element of set s1 with a key greater "
        << "than 20 is: " << *s1_RcIter << "." << endl;

   s1_RcIter = s1.upper_bound( 30 );

   // 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 greater than 30." << endl;
   else
      cout << "The element of set s1 with a key > 40 is: "
           << *s1_RcIter << "." << endl;

   // The element at a specific location in the set can be found 
   // by using a dereferenced iterator addressing the location
   s1_AcIter = s1.begin( );
   s1_RcIter = s1.upper_bound( *s1_AcIter );
   cout << "The first element of s1 with a key greater than"
        << endl << "that of the initial element of s1 is: "
        << *s1_RcIter << "." << endl;
}
  
  
  

必要条件

ヘッダー: <set>

名前空間: std

参照

関連項目

set Class

set::lower_bound, set::upper_bound, と set::equal_range

標準テンプレート ライブラリ