list::erase
Usuwa element lub zakres elementów na liście z określonym pozycji.
iterator erase( iterator _Where ); iterator erase( iterator _First, iterator _Last );
Parametry
_Where
Pozycja elementu, który ma zostać usunięty z listy._First
Pozycja pierwszego elementu usunięte z listy._Last
Pozycja poza ostatni element usunięty z listy.
Wartość zwracana
Sterująca dwukierunkowego, określający pierwszym elementem pozostałe poza wszelkie elementy usunięte lub wskaźnik na końcu listy, jeśli nie zawiera żadnego takiego elementu.
Uwagi
Nie ponowny występuje, Iteratory i odwołania stają się nieprawidłowe tylko dla elementów wymazywania.
Wymaż nigdy nie zgłasza wyjątek.
Przykład
// list_erase.cpp
// compile with: /EHsc
#include <list>
#include <iostream>
int main( )
{
using namespace std;
list <int> c1;
list <int>::iterator Iter;
c1.push_back( 10 );
c1.push_back( 20 );
c1.push_back( 30 );
c1.push_back( 40 );
c1.push_back( 50 );
cout << "The initial list is:";
for ( Iter = c1.begin( ); Iter != c1.end( ); Iter++ )
cout << " " << *Iter;
cout << endl;
c1.erase( c1.begin( ) );
cout << "After erasing the first element, the list becomes:";
for ( Iter = c1.begin( ); Iter != c1.end( ); Iter++ )
cout << " " << *Iter;
cout << endl;
Iter = c1.begin( );
Iter++;
c1.erase( Iter, c1.end( ) );
cout << "After erasing all elements but the first, the list becomes: ";
for (Iter = c1.begin( ); Iter != c1.end( ); Iter++ )
cout << " " << *Iter;
cout << endl;
}
Wymagania
Nagłówek: < listy >
Przestrzeń nazw: std