诡异之--map clear 之后可能导致size != 0的操作
map<char, int>mp;
charMp['a'] = ;
charMp['b'] ++;
cout<<charMp['a']<<endl;
cout<<charMp.size()<<endl;
charMp.clear();
cout<<"after clear:"<<endl;
cout<<charMp.size()<<endl;//0
//charMp.find('a');//find is ok !
cout<<charMp['a']<<endl;//0:虽然不存在,但是访问过后map中就出现了'a' -> 0: 神奇,这是STL中的bug?
for(auto &r : charMp){
cout<<r.first<<" , "<<r.second<<endl;//a , 0
}
cout<<charMp.size()<<endl;//
结论就是:以后涉及到map.size()操作的话,必须要用Find,不要使用这种直接式的mp['c']的查询方式, 很危险。
诡异之--map clear 之后可能导致size != 0的操作的更多相关文章
- empty()和size() == 0有区别吗
empty()和size() 这里说的empty()和size()都是STL的容器中提供的接口,分别用来判断当前容器是否为空和获取当前包含的元素个数 区别 其实按道理来说两者应该是相等的,而且STL容 ...
- mariadb:InnoDB: Error: log file ./ib_logfile0 is of different size 0 5242880 bytes
mariadb 启动中 InnoDB: Error: log file ./ib_logfile0 is of different size 0 起因:线上正在运行的系统,因为需要调整性能,变更了my ...
- java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@1f303192 rejected from java.util.concurrent.ThreadPoolExecutor@11f7cc04[Terminated, pool size = 0, active threads
java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@1f303192 rejec ...
- java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 错误
你的ArrayList 是一个没有值的对象(不是null),也就是里面什么对象也没有存(即:arrayList.size()==0).但是,你有取它下标为0值的操作.所以,数组越界了!!比如array ...
- caffe: test code 执行出问题: Check failed: FLAGS_weights.size() > 0 (0 vs. 0) Need model weights to score.
Check failed: FLAGS_weights.size() > 0 (0 vs. 0) Need model weights to score. 出现这个错误,但是我记得昨天还好好的, ...
- nginx: [emerg] the size 10485760 of shared memory zone "cache_one" conflicts with already declared size 0
注意配置段中的区域包含关系. proxy_cache_patch 要在proxy_cache前已经定义. what seems to be the problem? [emerg]: the size ...
- [转载] C++ STL中判断list为空,size()==0和empty()有什么区别
关于两个的区别,首先size()==0为bool表达式,empty()为函数调用,这一点很明显.查看源代码, bool empty() const { return _M_node->_M_ne ...
- jquery中判断选择器,找没找到元素用$().size()==0
jquery中判断选择器,找没找到元素用$().size()==0
- Java:List判空的条件:List=null 和 List.size = 0
当需要对一个LIst进行判空操作时我们可使用如下两个语句: if (list == null || list.size() == 0) {} if (list != null && l ...
随机推荐
- mesh topology for airfoil, wing, blade, turbo
ref Ch. 5, Anderson, CFD the basics with applications numerical grid generation foundations and appl ...
- Wind rotor states
test test Table of Contents 1. Wind rotor states 1.1. Turbulent Wake State 1.2. Vortex Ring State 1. ...
- scanf与getchar
如下: 5 5 R R R R R R R R R R R R R R R R R R R R R R R R R 只允许用scanf,如何写读取函数. 由于 ...
- 以位为单位存储标志-共用体-union
一.程序的结构如下: typedef union _KEYST { struct { uint8 Key1_Flag :1;//表示第0 ...
- jQuery WeUI 组件下拉刷新和滚动加载的实现
最近在做手机版使用到了下拉刷新和滚动加载,记录一下实现过程: 一.引入文件 ? 1 2 3 4 <link rel="stylesheet" href="Conte ...
- 【python】蛋疼的中文乱码解决方案
转自: http://yooooo.us/2013/python-encoding-decoding?variant=zh-cn
- 第5章 Cisco测试命令和TCP/IP连接故障处理
第5章 Cisco测试命令和TCP/IP连接故障处理 一.故障处理命令 1.show命令: 1) 全局命令: show version :显示系统硬件和软件版本.DRAM.Flash show sta ...
- Struts2框架复习(一)--最基本的struts2框架
前言 最近离职在家,发现之前学习的Struts2框架由于长时间不使用有点生疏,有鉴于此写下此文以备自己复习使用,同时也供大家批评指正. 准备工作 我觉得Struts2主要就是对Servlet的封装,还 ...
- 已知目标qps跟并发用户数20,压测平均响应时间实例
Jmeter性能测试案例(一) 转:https://blog.csdn.net/lovesoo/article/details/78579547 测试需求:测试20个用户访问网站在负载达到30QPS时 ...
- LeetCode 359. Logger Rate Limiter (记录速率限制器)$
Design a logger system that receive stream of messages along with its timestamps, each message shoul ...