map的成员函数
参考C++手册,可看到每个函数的参数返回值解释和使用举例:
https://zh.cppreference.com/w/cpp/container/map






实例


还可以直接使用:
simap[string("jerry")] = 10;
这个方式来赋值。因为重载了操作符[],所以会先检查关键字"jerry"是否存在,若存在则是修改value值,若不存在则是直接创建这个key并赋值value。
能用[]的原因是map的key唯一,但是如果是multimap的key不唯一,那么就不能使用[]操作符。因此multimap插入元素只能是使用insert(pair(key,value))
函数。

网友评论