basic_string::erase

Usuwa element lub szereg elementów w ciągu od określonej pozycji.

iterator erase(
    iterator _First, 
    iterator _Last
);
iterator erase(
    iterator _It
);
basic_string<CharType, Traits, Allocator>& erase(
    size_type _Pos = 0,
    size_type _Count = npos
);

Parametry

  • _First
    Iterację adresowania pozycja pierwszego elementu w zakresie mają zostać usunięte.

  • _Last
    Iterację adresowania pozycji jeden obok ostatniego elementu w zakresie mają zostać usunięte.

  • _It
    Iterację adresowania położenie elementu w ciągu ma być usunięty.

  • _Pos
    Indeks pierwszego znaku w ciągu, który ma zostać usunięty.

  • _Count
    Liczba elementów, które zostaną usunięte, jeśli istnieją dowolną liczbę z zakresu od początku ciągu z _Pos.

Wartość zwracana

Dla funkcji pierwszych dwóch elementów członkowskich iterację adresowania pierwszego znaku po ostatnim znakiem usuwane przez funkcję członka.Do trzeciego funkcji członka, odwołanie do obiektu string, z którego zostały usunięte elementy.

Uwagi

Zwraca wartość funkcji trzeciego członka * to.

Przykład

// basic_string_erase.cpp
// compile with: /EHsc
#include <string>
#include <iostream>

int main( ) 
{
   using namespace std;

   // The 1st member function using a range demarcated
   // by iterators
   string str1 ( "Hello world" );
   basic_string <char>::iterator str1_Iter;
   cout << "The original string object str1 is: " 
        << str1 << "." << endl;
   str1_Iter = str1.erase ( str1.begin ( ) + 3 , str1.end ( ) - 1 );
   cout << "The first element after those removed is: "
        << *str1_Iter << "." << endl;
   cout << "The modified string object str1 is: " << str1 
           << "." << endl << endl;

   // The 2nd member function erasing a char pointed to 
   // by an iterator
   string str2 ( "Hello World" );
   basic_string <char>::iterator str2_Iter;
   cout << "The original string object str2 is: " << str2
        << "." << endl;
   str2_Iter = str2.erase ( str2.begin ( ) + 5 );
   cout << "The first element after those removed is: "
        << *str2_Iter << "." << endl;
   cout << "The modified string object str2 is: " << str2 
        << "." << endl << endl;

   // The 3rd member function erasing a number of chars 
   // after a char
   string str3 ( "Hello computer" ), str3m;
   basic_string <char>::iterator str3_Iter;
   cout << "The original string object str3 is: " 
        << str3 << "." << endl;
   str3m = str3.erase ( 6 , 8 );
   cout << "The modified string object str3m is: " 
        << str3m << "." << endl;
}
  

Wymagania

Nagłówek: <ciąg>

Przestrzeń nazw: std

Zobacz też

Informacje

basic_string — Klasa