Translations of this page?:

erase

Sintaxe:

    #include <string>
    iterator erase( iterator loc );
    iterator erase( iterator start, iterator end );
    basic_string& erase( size_type index = 0, size_type num = npos );

A função erase():

  • remove o caracter apontado por loc, devolvendo um iterador para o caracter a seguir ao último caracter removido
  • remove todos os caracteres entre start e end, devolvendo um iterador para o caracter seguinte (not the one at end)
  • remove num caracteres começando em index, devolvendo a string modificada. Os parâmetros index e num têm valores por defeito, que significa que erase() pode ser invocada apenas com index para apagar todos os caracteres depois de index ou sem argumentos para apagar todos os caracteres.

Por exemplo:

  string s("So, you like donuts, eh? Well, have all the donuts in the world!");
  cout << "The original string is '" << s << "'" << endl;
 
  s.erase( 50, 13 );
  cout << "Now the string is '" << s << "'" << endl;
  s.erase( 24 );
  cout << "Now the string is '" << s << "'" << endl;
  s.erase();
  cout << "Now the string is '" << s << "'" << endl;

irá mostrar

  The original string is 'So, you like donuts, eh? Well, have all the donuts in the world!'
  Now the string is 'So, you like donuts, eh? Well, have all the donuts!'
  Now the string is 'So, you like donuts, eh?'
  Now the string is ''

erase() corre em tempo linear.

Tópicos Relacionados: insert

 
• • • SitemapRecent changesRSScc