Перевод этой страницы?:

find

Синтаксис:

    #include <string>
    size_type find( const string& str, size_type index = 0 ) const;
    size_type find( const charT* str, size_type index = 0 ) const;
    size_type find( const charT* str, size_type index, size_type length ) const;
    size_type find( charT ch, size_type index = 0 ) const;

Метод find возвращает:

  1. первое вхождение строки str в текущей строке, начиная с индекса index, или string::npos, если ничего не найдено,
  2. первые length символов строки str внутри текущей строки, начиная с индекса index, или string::npos, если ничего не найдено.

Например:

    string str1( "Alpha Beta Gamma Delta" );
    string::size_type loc1 = str1.find( "Omega", 0 );
    string::size_type loc2 = str1.find( "Gamma", 0 );
    if( loc1 != string::npos ) {
        cout << "Found Omega at " << loc1 << endl;
    } else {
        cout << "Didn't find Omega" << endl;
    }
    if( loc2 != string::npos ) {
        cout << "Found Gamma at " << loc2 << endl;
    } else {
        cout << "Didn't find Gamma" << endl;
    }

Результат кода:

Didn't find Omega
Found Gamma at 11

Смотрите также: find_first_not_of, find_first_of, find_last_not_of, find_last_of, rfind