vector map迭代器失效解决方案
2024-08-25 11:06:46
vector :
iter = container.erase(iter); //erase的返回值是删除元素下一个元素的迭代器
vector<int>::iterator it = a.begin();
for(;it !=a.end();)
{
printf("%d\n",*it);
it = a.erase(it);
}
map:
dataMap.erase(iter++)
注:map erase 没有返回下一个迭代器的方法
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
using namespace std; int main(int argc, char *argv[])
{
vector<int>a;
a.push_back();
a.push_back();
a.push_back();
a.push_back();
vector<int>::iterator it = a.begin();
for(;it !=a.end();)
{
printf("%d\n",*it);
it=a.erase(it);
}
map<int,int>b;
b[]=;
b[]=;
b[]=;
b[]=;
map<int,int>::iterator it1 = b.begin();
for(;it1!=b.end();)
{
printf("%d\n",it1->first);
b.erase(it1++);
} }
最新文章
- sql语句修改字段长度
- Emacs-24.1 + ECB-2.40 + cscope-15.7a + cedet 无root权限指定目录安装与配置
- vs---错误收集并自己解决后归纳
- 移动端调试工具推荐 小苹果和debugap
- esc设置多站点 域名解析
- JDBC和JPA调用储存过程 接收存储过程有返回值
- Matlab中plot、fplot、ezplot的使用方法和区别
- 【Xamarin开发 Android 系列 6】 Android 结构基础(上)
- 排序 O(nlogn)
- PND_白盾
- 从汇编看c++内联函数评估求值
- FineUI开源版之TreeGrid实现
- (cljs/run-at (JSVM. :browser) ";搭建刚好可用的开发环境!";)
- nopCommerce 3.9 大波浪系列 之 汉化-中文语言
- Unhandled event loop exception No more handles
- Python之sqlite3
- 【纯&#183;技术干货】更 App 化的小程序开发
- U盘被写保护不能重新格式化
- php 常用的标签比较
- luoguP3366 [模板] 最小生成树
热门文章
- python基础25 -----python高级用法
- Android:日常学习笔记(8)———探究UI开发(3)
- jQuery中的部分方法
- $《第一行代码:Android》读书笔记——第6章 数据持久化
- JAVA ArrayUtils 数组工具类
- Android摄像头测量尺(Advanced Ruler Pro)使用方法
- 解决Newtonsoft.Json版本问题
- poj 1905 Expanding Rods(木杆的膨胀)【数学计算+二分枚举】
- Oracle常用知识小总结
- JAVA使用Freemarker生成静态文件中文乱码