Translations of this page?:

find

Syntax:

    #include <set>
    iterator find( const key_type& key );
    const_iterator find( const key_type& key ) const;

The find() function returns an iterator to key, or an iterator to the end of the multiset if key is not found.

For example, the following code uses find() to find and remove a single matching element:

    multiset<int> ms;
    multiset<int>::iterator iter;
    int i;
 
    for (i = 1; i < 5; i++) {
        ms.insert(i);
        ms.insert(i*i);
        ms.insert(i-1);
    }
 
    cout << "ms is:" ;
    for (iter = ms.begin(); iter != ms.end(); ++iter)
        cout << " " << *iter;
    cout << "." << endl;
 
    iter = ms.find( 3 );
    if ( iter != ms.end() ) {
        ms.erase( iter );
    }
 
    cout << "ms is now:" ;
    for (iter = ms.begin(); iter != ms.end(); ++iter)
        cout << " " << *iter;
    cout << "." << endl;

The above code produces the following output:

ms is: 0 1 1 1 2 2 3 3 4 4 9 16.
ms is now: 0 1 1 1 2 2 3 4 4 9 16.

Note that only a single 3 was removed.

find() runs in logarithmic time.

 
• • • IndexRecent changesRSScc