Translations of this page?:

find

Syntax:

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

find()関数は、キーと一致する キー/値の組を返します。もし、マップ終端のイテレータが返された場合は、キーが見つからなかったことを示します。

find()の処理時間は、対数時間です。

たとえば、次のコードは、ユーザから入力された単語を数え、特定の単語を見つけるためにfind()を使用しています。

    map<string,int> stringCounts;
    string str;
 
    while( cin >> str ) ++stringCounts[str];
 
    map<string,int>::iterator iter = stringCounts.find("spoon");
    if( iter != stringCounts.end() ) {
      cout << "You typed '" << iter->first << "' " << iter->second << " time(s)" << endl;
    }

実行時に次の入力をすると

  my spoon is too big.  my spoon is TOO big!  my SPOON is TOO big!  I am a BANANA!

次の表示結果が得られます。

  You typed 'spoon' 2 time(s)
 
• • • SitemapRecent changesRSScc