std::set::find
Z cppreference.com
iterator find( const Key& key ); |
(1) | |
const_iterator find( const Key& key ) const; |
(2) | |
Znajduje element, którego klucz przy porównaniu jest równy key.
Parametry
| key | - | wartość klucza, z którym element będzie szukany |
Zwracana wartość
Iterator wskazujący na element z kluczem równym key. Jeśli nie ma takiego elementu w kontenerze, zwracany jest iterator zakońcowy(ang) (zobacz end()).
Złożoność
Logarytmiczna względem rozmiaru kontenera.
Przykład
#include <iostream>
[[:Szablon:cpp/container/correct include assoc]]
int main()
{
std::set<int> example = {1, 2, 3, 4};
auto search = example.find(2);
if(search != example.end()) {
std::cout << "Found " << (*search) << '\n';
}
else {
std::cout << "Not found\n";
}
}
Wynik:
Found 2
Zobacz także
| zwraca liczbę elementów o podanym kluczu (publiczna metoda) | |