STL map 容器 解读
发布时间
阅读量:
阅读量
成员方法
map容器的迭代器中包含first()和second()两个成员,其中second用于存储数据,并能够返回相应的值。
创建
map容器模板的定义如下所示:
template < class Key, // 指定键(key)的类型
class T, // 指定值(value)的类型
class Compare = less<Key>, // 指定排序规则
class Alloc = allocator<pair<const Key,T> > // 指定分配器对象的类型
> class map;
插入
第一种方式:将键值对数据添加至 map 容器中
map<int, string> mapStudent;
mapStudent.insert(pair<int, string>(1,“第一种”)
全部评论 (0)
还没有任何评论哟~
