vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
vector<int>::iterator it=v.begin();
v.push_back(4);
cout<<*it; //输出不为1,vector 容量在上面push_bach时已改变,之前的迭代器失效;指针,引用也都失效
stl之vector的iterator坑
最新推荐文章于 2023-12-21 19:15:00 发布
vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
vector<int>::iterator it=v.begin();
v.push_back(4);
cout<<*it; //输出不为1,vector 容量在上面push_bach时已改变,之前的迭代器失效;指针,引用也都失效