Aracılığıyla paylaş


set::find

Belirtilen anahtar için eşdeğer bir anahtara sahip bir küme içindeki bir öğenin konumunu adresleme bir yineleyici döndürür.

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

Parametreler

  • _Key
    Aranmakta kümesinden bir öğe sıralama anahtarı tarafından anahtarın eşleştirilmesi gereken bağımsız değişkeni.

Dönüş Değeri

Bir yineleyici ya da const_iterator , belirtilen anahtar için eşdeğer bir öğenin konumunu adresleri veya kümesindeki son öğe anahtarı için eşleşme bulunursa, izleyen konum yöneliktir.

Notlar

Üye işlevi olan sýralama anahtarýdýr bağımsız değişken anahtarı altında bir sipariş işleminiz ikili bir yüklemi eşdeğer kümesi içinde bir öğe gideren bir yineleyici üzerinde daha az verir-comparability ilişkisi'den.

Dönüş değeri bulmak için atanmış bir const_iterator, kümesi nesnesi değiştirilemez.Dönüş değeri bulmak için atanmış bir Yineleyici, set nesne değiştirilebilir.

Örnek

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

   s1_RcIter = s1.find( 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 addressing the location
   s1_AcIter = s1.end( );
   s1_AcIter--;
   s1_RcIter = s1.find( *s1_AcIter );
   cout << "The element of s1 with a key matching "
        << "that of the last element is: "
        << *s1_RcIter << "." << endl;
}
  
  
  

Gereksinimler

Başlık: <set>

Namespace: std

Ayrıca bkz.

Başvuru

set Class

set::find (STL Samples)

Standart Şablon Kütüphanesi