Translations of this page?:

substr

Sintaxe:

    #include <string>
    string substr( size_type index = 0, size_type length = npos ) const;

O método substr da classe string deolve uma substring da string actual, começando em index, e com length caracteres de comprimento.

Se index + length ultrapassa o fim da string, então só o resto da string começada em index será devolvido.

Se length for omitido, tomará por defeito o valor string::npos, e substr simplesmente devolve o resto da string começando em index.

Por exemplo:

     string s("What we have here is a failure to communicate");
     string sub = s.substr(21);
     cout << "The original string is " << s << endl;
     cout << "The substring is " << sub << endl;

mostra

     The original string is What we have here is a failure to communicate
     The substring is a failure to communicate

Tópicos Relacionados: copy

 
• • • SitemapRecent changesRSScc