次の方法で共有


multiset::find

指定したキーと同じキーを持つ複数セットに要素の初期位置を指定する反復子を返します。

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

パラメーター

  • _Key
    検索された複数の要素の並べ替えキーが一致するキー。

戻り値

一致するキーにある [反復子]const_iterator 指定したキーを持つ要素の初期位置をアドレス、または複数セットに最後の要素の次の場所。

解説

このメンバー関数は、並べ替えキーが比較可能な関係によりも少ない基づいて命令を引き起こすバイナリ述語の下の引数のキーと同じに多重セットの要素を指定する反復子を返します。

find の戻り値が const_iteratorに設定すると、複数のオブジェクト セットは変更できません。find の戻り値が **[反復子]**に設定すると、複数のオブジェクト セットを変更できます。

使用例

// multiset_find.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( 20 );

   ms1_RcIter = ms1.find( 20 );
   cout << "The first element of multiset ms1 with a key of 20 is: "
        << *ms1_RcIter << "." << endl;

   ms1_RcIter = ms1.find( 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 dereferenced iterator addressing the location
   ms1_AcIter = ms1.end( );
   ms1_AcIter--;
   ms1_RcIter = ms1.find( *ms1_AcIter );
   cout << "The first element of ms1 with a key matching" << endl
        << "that of the last element is: "
        << *ms1_RcIter << "." << endl;

   // Note that the first element with a key equal to
   // the key of the last element is not the last element
   if ( ms1_RcIter == --ms1.end( ) )
      cout << "This is the last element of multiset ms1."
           << endl;
   else
      cout << "This is not the last element of multiset ms1."
           << endl;
}
  
  
  
  

必要条件

ヘッダー: <set>

名前空間: std

参照

関連項目

multiset Class

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