首页 > 其他 > 详细

STL map 用法

时间:2017-11-03 15:07:39      阅读:283      评论:0      收藏:0      [点我收藏+]

包含头文件

#include <iostream>

#include <string>

#include <map>


1 数据的插入

std::map<int, std::string> mapStudent;

//插入数组,数组的下标实际上就是索引

mapStudent[4] = "fengyuzaitu@126.com";


2 数据的遍历

std::map<int, std::string>::iterator iter;

iter = mapStudent.find(5);

//访问不到数据的判断

if (iter == mapStudent.end()) return;


3 数据的删除

std::cout << iter->second << std::endl;

//删除该记录

mapStudent.erase(iter);


注意:

对于容器而言,是否已经遍历完容器数据,是根据iter是否已经迭代到end()


STL map 用法

原文:http://fengyuzaitu.blog.51cto.com/5218690/1978716

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!