pre{
line-height:1;
color:#f0caa6;
background-color:#2d161d;
font-size:16px;}.sysFunc{color:#e54ae9;font-style:italic;font-weight:bold;}
.selfFuc{color:#f1f9be;}
.bool{color:#69305e;}
.condition{color:#628698;font-weight:bold;}
.key{color:#e336b6;}
.var{color:#008080;font-style:italic;}
.Digit{color:#808080;font-weight:bold;}
.includePre{color:#a6caf0;}
.operator {color:#ce0c40;font-weight:bold;}
vector::erase
Removes an element or a range of elements in a vector from specified positions.
iterator erase(
iterator _Where
);
iterator erase(
iterator _First,
iterator _Last
);
Return Value
An iterator that designates the first element remaining beyond any elements removed, or a pointer to the end of the vector if no such element exists.
Example
// vector_erase.cpp
// compile with: /EHsc
#include <vector>
#include <iostream>
int main( )
{
using namespace std;
vector <int> v1;
vector <int>::iterator Iter;
v1.push_back( 10 );
v1.push_back( 20 );
v1.push_back( 30 );
v1.push_back( 40 );
v1.push_back( 50 );
cout << "v1 =" ;
for ( Iter = v1.begin( ) ; Iter != v1.end( ) ; Iter++ )
cout << " " << *Iter;
cout << endl;
v1.erase( v1.begin( ) );
cout << "v1 =";
for ( Iter = v1.begin( ) ; Iter != v1.end( ) ; Iter++ )
cout << " " << *Iter;
cout << endl;
v1.erase( v1.begin( ) + 1, v1.begin( ) + 3 );
cout << "v1 =";
for ( Iter = v1.begin( ) ; Iter != v1.end( ) ; Iter++ )
cout << " " << *Iter;
cout << endl;
}
v1 = 10 20 30 40 50
v1 = 20 30 40 50
v1 = 20 50
Requirements
Header: <vector>
Namespace: std
本文使用 书画小说软件 发布,内容与软件无关,书画小说软件 更惬意的读、更舒心的写、更轻松的发布。