◐ Shell
clean mode source ↗

std::map::find - cppreference.com

Da cppreference.com.

Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.

La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui.

Click here for the English version of this page

<metanoindex/>

<tbody> </tbody>

iterator find( const Key& key );

const_iterator find( const Key& key ) const;

Trova un elemento con key chiave.

Original:

Finds an element with key key.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Parametri

key -

valore della chiave dell'elemento da cercare

Original:

key value of the element to search for

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Valore di ritorno

Iterator di un elemento con key chiave. Se tale elemento non viene trovato, past-the-end (vedi end()) iteratore viene restituito.

Original:

Iterator to an element with key key. If no such element is found, past-the-end (see end()) iterator is returned.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Complessità

Logarithmic in the size of the container.

Vedi anche

mihai are mere

restituisce il numero di elementi corrispondenti chiave specifica

Original:

returns the number of elements matching specific key

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(metodo pubblico) [modifica]

Demonstrates the risk of accessing non-existing elements via operator [].

#include <string>
#include <iostream>
#include <map>
 
int main()
{
    typedef std::map<std::string,int>  mapT;
 
    mapT my_map;
    my_map["first"]=  11;
    my_map["second"]= 23;
 
    mapT::iterator  it= my_map.find("first");
    if( it != my_map.end() ) std::cout << "A: " << it->second << "\n";
 
    it= my_map.find("third");
    if( it != my_map.end() ) std::cout << "B: " << it->second << "\n";
 
    // Accessing a non-existing element creates it
    if( my_map["third"] == 42 ) std::cout << "Oha!\n";
 
    it= my_map.find("third");
    if( it != my_map.end() ) std::cout << "C: " << it->second << "\n";
 
    return 0;
}

Output: