Поделиться через


multiset::find

Возвращает итератор адресацию первое положение элемента в мультинабора, который содержит ключевое эквивалентно заданному ключу.

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

Параметры

  • _Key
    Ключ, который будет соответствовать ключ сортировки элемента из multiset, в котором выполняется поиск.

Возвращаемое значение

iterator или const_iterator адресации первое положение элемента с заданным ключом или расположение преуспевая последний элемент мультинабора, если совпадение не найдено для ключа.

Заметки

Функция-член возвращает итератор, который обращается элемент мультинабора, ключ сортировки совпадает с ключом аргумента предиката в двоичным накладывает на основе упорядочения, чем соединение сопоставляемости.

Если возвращаемое значение find присвоено const_iterator, то объект мультинаборов не может быть изменен.Если возвращаемое значение find присвоено iterator, то объект мультинабора можно изменять.

Пример

// 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

Стандартная библиотека шаблонов