Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
Restituisce un iteratore che indirizza la prima posizione di un elemento in un multi-insieme con un equivalente principale in una chiave specificata.
iterator find(
const Key& _Key
);
const_iterator find(
const Key& _Key
) const;
Parametri
- _Key
La chiave da corrispondere alla chiave di ordinamento di un elemento da multi-insieme cercato.
Valore restituito
iterator o const_iterator destinato alla prima posizione di un elemento con una chiave specificata, o il percorso che è l'ultimo elemento a multi-insieme se non viene rilevata alcuna corrispondenza della chiave.
Note
La funzione membro restituisce un iteratore destinato a un elemento in multi-insieme della chiave di ordinamento è equivalente alla chiave dell'argomento in un predicato binario che provoca un ordine base a meno che la relazione di comparabilità.
Se il valore restituito find viene assegnato a const_iterator, l'oggetto di multi-insieme non può essere modificato.Se il valore restituito find viene assegnato a iterator, l'oggetto di multi-insieme può essere modificato.
Esempio
// 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;
}
Requisiti
intestazione: <set>
Spazio dei nomi: deviazione standard