成员方法
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,“第一种”));
第二种:在当前 map 容器中的指定位置处构造新键值对。其效果和插入键值对一样,但效率更高。(不知道是不是真的效率高)
myMap.emplace(11,"第二种");
map各种查询
map嵌套vector,查询键值方法:
//vector嵌套vector
int mode = 6;
vector<vector<int> > ivec(mode); //6行
//插入值
for (int i2 = 0; i2 < ivec.size(); i2++) {
//行
for (int i = 0; i <= 3; i++