本文共 3192 字,大约阅读时间需要 10 分钟。
接着学习map容器的常见API操作,依然是大部分前面学习过的,名称相同的API的基本调用测试。本篇学习map容器大小相关API,然后学习容器交换,容器元素插入和删除,清空等操作。
1.map容器大小操作
统计map容器大小的函数原型
#include #include #include
运行结果
数字0表示非空,数字1表示容器为空
2.map容器交换
函数原型还是swap(map)
#include #include #include
运行结果
3.map容器插入和删除
相关插入和删除函数原型
插入这里不重复,就是前面一直在使用的insert()函数。
#include #include #include
测试结果
4.map容器查找和统计
接着来看看查找和统计的API
#include #include #include
测试结果
转载地址:http://texws.baihongyu.com/