#include<algorithm>
#include<vector>
#include<iostream>
#include<iterator>
using namespace std;
void main()
{
vector<int> coll;
coll.push_back(4);
coll.push_back(3);
coll.push_back(37);
coll.push_back(37);
coll.push_back(30);
cout<<coll.size()<<endl;
vector<int>::iterator pos;
for(pos = coll.begin();pos != coll.end();++pos)
cout<<*pos<<' ';
unique(coll.begin(),coll.end());
cout<<coll.size()<<endl;
for(pos = coll.begin();pos != coll.end();++pos)
cout<<*pos<<" ";
int i;
cin>>i;
}
结果为:
将不需要被移除的元素往前覆盖被移除的元素,因此不改变区间内的个数,而是返回逻辑上的新终点位置。