//要使用map对象,刚必须包含map头文件。在定义map对象时,必须分别指明键和值的类型
//
//默认情况下,标准库使用键类型定义的<操作符来实现键的比较
//
//在学习map的接口时,需谨记value_type是pair类型,它的值成员可以修改,但键成员不能修改
#include
#include
#include
using namespace std;
using std::string;
void main(){
mapint> word_count;
mapint>::iterator map_ip=word_count.begin();
cout<first;
cout<<" "<second;
/* map_ip->first="new key";*/
++map_ip->second;
mapint>::key_type;
mapint>::value_type;
}
本文介绍了C++标准模板库中的Map容器使用方法,包括如何定义Map对象、迭代器的使用及注意事项。文中通过示例展示了如何操作Map中的键值对,并强调了键不可更改而值可以更改的特点。

被折叠的 条评论
为什么被折叠?



