Translations of this page?:

find

Sintaxe:

    #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;

O método find devolve:

  1. a primeira ocorrência de str na string actual, começando em index, ou string::npos se nada for encontrado
  2. os primeiros length caracteres de str na string actual, começando em index, ou string::npos se nada for encontrado.

Por exemplo:

    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;
    }

O resultado é

Didn't find Omega
Found Gamma at 11

Tópicos Relacionados: find_first_not_of, find_first_of, find_last_not_of, find_last_of, rfind

 
• • • SitemapRecent changesRSScc