zoukankan
html css js c++ java
STL中用erase()方法遍历删除元素
STL中的容器按存储方式分为两类,一类是按以数组形式存储的容器(如:vector 、deque);另一类是以不连续的节点形式存储的容器(如:list、set、map)。在使用erase方法来删除元素时,需要注意一些问题。
在 使用 list、set 或 map遍历删除某些元素时可以这样使用:
正确使用方法1
std::list< int> List;
std::list< int>::iterator itList;
for( itList = List.begin(); itList != List.end(); )
{
if( WillDelete( *itList) )
{
itList = List.erase( itList);
}
else
itList++;
}
在使用 vector、deque遍历删除元素时,也可以通过erase的返回值来获取下一个元素的位置:
正确使用方法
std::vector< int> Vec;
std::vector< int>::iterator itVec;
for( itVec = Vec.begin(); itVec != Vec.end(); )
{
if( WillDelete( *itVec) )
{
itVec = Vec.erase( itVec);
}
else
itList++;
}
查看全文
相关阅读:
后端——框架——日志框架——logback——《官网》阅读笔记——第三章节(配置文件)
后端——框架——日志框架——logback——《官网》阅读笔记——第四章节(Appender)——待完善
后端——框架——日志框架——logback——《官网》阅读笔记——第五章节(Encoder)
后端——框架——日志框架——logback——《官网》阅读笔记——第六章节(Layout和日志格式)
后端——框架——日志框架——logback——《官网》阅读笔记——第七章节(Filter)
后端——框架——日志框架——logback——《官网》阅读笔记——第八章节(多线程场景&MDC对象)
后端——框架——日志框架——logback——《官网》阅读笔记——第九章节(多应用)——待完善
后端——框架——日志框架——logback——《官网》阅读笔记——第十章节(JMX)
后端——框架——日志框架——logback——《官网》阅读笔记——第十一章节——待补充
后端——框架——日志框架——logback——《官网》阅读笔记——第十二章节——待补充
原文地址:https://www.cnblogs.com/tuzhiye/p/1688326.html
最新文章
Adapter数据变化改变现有View的实现
Android手机信号
Android应用关闭,重启
开始使用Fresco
Fresco框架的介绍
android设置系统时间
《APK瘦身实践》
android framework源码编译流程
EventBus使用
android事件总线EventBus解析
热门文章
文件下载
nodejs的学习
shell脚本的练习
enum
oauth 理解
spring-shiro 配置
idea 一些设置
queue队列
classpath 路径和classpath*的区别
WebService 生成客户端
Copyright © 2011-2022 走看看