#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<int> array;
array.push_back(6);
array.push_back(3);
array.push_back(6);
array.push_back(6);
array.push_back(2);
vector<int>::iterator itor = array.begin();
int nSize = array.size();
int i = 0;
for (int i = 0; i < nSize ;)
{
if (*itor == 6)
{
array.erase(itor);
itor = array.begin() + i;//这句是必须的,好像itor并不会自动指向下一个
nSize--;
}
else
{
i++;
itor++;
}
}
itor=array.begin();
for(itor=array.begin();itor!=array.end();)
{
cout<<(*itor++);
}
getchar();
return 0;
}
Vector earse的正确用法
最新推荐文章于 2023-06-15 20:24:42 发布