The erase () function of the container (container), which deletes an element, moves the pointer of the iterator and points to the next element;
An iterator (iterator) is a pointer to an assigned address that points to the same element;
Code:
* * * test.cpp * * Created on:2014.04.18 *
author:spike/
/*eclipse CDT, gcc 4.8.1* /
#include <iostream>
#include <vector>
using namespace std;
int main () {
Std::vector<int> VI = {1, 6, 6, 3};
Std::vector<int>::iterator Iter1;
Std::vector<int>::iterator Iter2;
Less delete a 6 for
(Iter1 = Vi.begin (); Iter1!= vi.end (); ++iter1) {
if (6 = *iter1) {
iter2 = iter1;
Vi.erase (iter2);
--iter1
}
}
Std::cout << "vector size is:" << vi.size () << Std::endl;
for (Iter1 = Vi.begin (); Iter1!= vi.end (); ++iter1) {
std::cout << *iter1 << "";
}
Std::cout << Std::endl;
return 0;
}
Output:
Vector size Is:3
1 6 3
Author: csdn Blog spike_king
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/cplus/