标准模板库(STL)之 map 用法【初级】
STL--map常用函数

STL--map常⽤函数// testSTLMap.cpp : 测试STL map常⽤⽅法//#include "stdafx.h"#include <string>#include <map>#include <iostream>using namespace std;int _tmain(int argc, _TCHAR* argv[]){map<int,string> mapStu;//使⽤pair插⼊数据mapStu.insert(pair<int,string>(1,"luo"));mapStu.insert(pair<int,string>(2,"xiong")); //使⽤map的value_type插⼊函数mapStu.insert(map<int,string>::value_type(3,"doudou"));//使⽤pair来判断插⼊是否成功pair<map<int,string>::iterator,bool> result;result = mapStu.insert(map<int,string>::value_type(4,"jinxiong"));if (result.second == false){cout<<"false"<<endl;}else{cout<<"true"<<endl;}mapStu[4]="bao"; //find函数返回查询key所在的迭代器map<int,string>::iterator iterFind = mapStu.find(1);mapStu.erase(iterFind);//适⽤迭代器遍历mapfor(map<int,string>::iterator iter = mapStu.begin();iter!=mapStu.end();iter++){cout<<"first:"<<iter->first<<" second:"<<iter->second<<endl;}//map包含数据的⼤⼩cout<<"size of the map:"<<mapStu.size()<<endl;//map中某个key出现的次数,只返回0或者1cout<<"count of the 2:"<<mapStu.count(5)<<endl;//清空mapmapStu.clear();//判断map是否为空if (mapStu.empty()){cout<<"map is empty!"<<endl;}else{cout<<"map is not empty!"<<endl;}typedef struct studentInfo{int s_id_;string strName;//必须重载bool operator<(const studentInfo& stu)const{if (stu.s_id_>s_id_){return true;}else return false;}}stuInfo,*p_stuInfo;stuInfo student;student.s_id_ = 3;student.strName = "luo";//stuInfo必须重载⼩于号操作符,否则报错map<stuInfo,int> mapScore;mapScore.insert(pair<stuInfo,int>(student,80));student.s_id_ = 2;student.strName = "xiong";mapScore.insert(map<stuInfo,int>::value_type(student,90));typedef struct studentInfo2{int s_id_;string strName;}stuInfo2,*p_stuInfo2;//必须实现仿函数class sortA{public:bool operator()(const stuInfo2& stu1,const stuInfo2& stu2)const{if (stu1.s_id_<stu2.s_id_){return true;}else return false;}};stuInfo2 student2;student2.s_id_ = 3;student2.strName = "luo";//必须加⼊仿函数sortA,否则报错map<stuInfo2,int,sortA> mapScore2;mapScore2.insert(pair<stuInfo2,int>(student2,80));student2.s_id_ = 2;student2.strName = "xiong";mapScore2.insert(map<stuInfo2,int>::value_type(student2,90)); return0;}。
C++学习---STL常用容器之map容器

C++学习---STL常⽤容器之map容器8、map/multimap 容器8.1、map基本概念简介:map中所有元素都是pairpair中第⼀个元素为key(键值),起到索引作⽤,第⼆个元素为value(实值)所有元素都会根据元素的键值⾃动排序本质:map/multimap属于关联式容器,底层结构是⽤⼆叉树实现。
优点:可以根据key值快速找到value值map和multimap的区别:map不允许容器中有重复key值元素multimap允许容器中有重复key值元素8.2、map构造和赋值#include <iostream>#include <map>using namespace std;/*map<T1,T2> mp; //map默认构造函数map(const map &mp); //拷贝构造函数map& operator=(const map & mp); //重载等号操作符*///map容器构造和赋值void printMap(map<int, int> &m) {for (map<int, int>::iterator it = m.begin(); it != m.end(); it++) {cout << "key = " << (*it).first << " value = " << it->second << endl;}cout << endl;}void test01() {//创建map容器,默认构造map<int, int> m;//匿名对组放⼊容器中,默认按照key排序m.insert(pair<int,int>(1,10));m.insert(pair<int,int>(6,60));m.insert(pair<int,int>(3,30));m.insert(pair<int,int>(4,40));printMap(m);//拷贝构造map<int, int> m2(m);printMap(m2);//赋值map<int, int> m3;m3 = m2;printMap(m3);}int main() {test01();system("pause");return0;}8.3、map⼤⼩和交换#include <iostream>#include <map>using namespace std;/*size(); //返回容器中元素的数⽬empty(); //判断容器是否为空swap(st); //交换两个集合容器*///map容器的⼤⼩和交换void printMap(map<int, int> &m) {for (map<int, int>::iterator it = m.begin(); it != m.end(); it++) {cout << "key:" << it->first << " value:" << it->second << endl; }cout << endl;}void test01() {map<int, int> m;m.insert(pair<int,int>(1,10));m.insert(pair<int,int>(6,60));m.insert(pair<int,int>(3,30));m.insert(pair<int,int>(4,40));if (m.empty()) {cout << "m为空" << endl;}else {cout << "m不为空" << endl;}cout << "m的⼤⼩:" << m.size() << endl;}//交换void test02() {map<int, int> m1;m1.insert(pair<int,int>(1,10));m1.insert(pair<int,int>(2,20));m1.insert(pair<int,int>(3,30));map<int, int> m2;m2.insert(pair<int, int>(5, 500));m2.insert(pair<int, int>(6, 600));cout << "交换前:" << endl;printMap(m1);printMap(m2);m1.swap(m2);cout << "交换后:" << endl;printMap(m1);printMap(m2);}int main() {test01();test02();system("pause");return0;}8.4、map插⼊和删除#include <iostream>#include <map>using namespace std;/*insert(elem); //在容器中插⼊元素clear(); //清除所有元素erase(pos); //删除pos迭代器所指的元素,返回下⼀个元素的迭代器erase(beg,end);//删除区间[beg,end]的所有元素,返回下⼀个元素的迭代器erase(key); //删除容器中值为key的元素*///map容器的插⼊和删除void printMap(map<int, int> &m) {for (map<int, int>::iterator it = m.begin(); it != m.end(); it++) {cout << "key:" << it->first << " value:" << it->second << endl;}cout << endl;}void test01() {map<int, int> m;//第⼀种m.insert(pair<int,int>(1,10));m.insert(pair<int,int>(6,60));//第⼆种m.insert(make_pair(2,20));//第三种m.insert(map<int,int>::value_type(3,30));//第四种,不建议使⽤[]插⼊m[5] = 40;//利⽤key有值的情况进⾏值的访问;//否则在key没有值的情况下,默认给值赋值为0,访问得到0cout << m[2] << endl;printMap(m);//删除m.erase(m.begin());printMap(m);//按照key删除,有则删除m.erase(3);printMap(m);//按照区间的⽅式删除,相当于清空//m.erase(m.begin(),m.end());m.clear();printMap(m);}int main() {test01();system("pause");return0;}8.5、map查找和统计函数原型:find(key); //查找key是否存在,若存在,返回该键的元素的迭代器;若不存在,返回map.end();count(key);//统计key的元素个数#include <iostream>#include <map>using namespace std;/*find(key); //查找key是否存在,若存在,返回该键的元素的迭代器;若不存在,返回map.end();count(key);//统计key的元素个数*///map容器的查找和统计void test01() {map<int, int> m;m.insert(pair<int,int>(1,10));m.insert(pair<int,int>(4,40));//map不允许插⼊重复的keym.insert(pair<int,int>(4,30));m.insert(pair<int,int>(2,20));map<int,int>::iterator pos = m.find(4);if (pos != m.end()) {cout << "查找到了元素 key=" << pos->first << " value=" << pos->second << endl; }else {cout << "未找到元素" << endl;}//统计,cout统计⽽⾔count统计⽽⾔,结果要么是 0,要么是1.//mutimap可以⼤于1int num = m.count(4);cout << "num = " << num << endl;}int main() {test01();system("pause");return0;}8.6、map容器排序利⽤仿函数可以改变排序规则#include <iostream>#include <map>using namespace std;/*map容器默认排序规则为按照key值进⾏从⼩到⼤排序利⽤仿函数可以改变排序规则,即重载了函数调⽤⼩括号*/class MyCompare {public:bool operator()(int v1, int v2){//降序return v1 > v2;}};void printMap(map<int, int, MyCompare> &m) {for (map<int, int, MyCompare>::iterator it = m.begin(); it != m.end(); it++) {cout << "key:" << it->first << " value:" << it->second << endl;}cout << endl;}//map容器的排序void test01() {//指定仿函数map<int, int, MyCompare> m;m.insert(pair<int,int>(1,10));m.insert(make_pair(2,20));m.insert(make_pair(5,50));m.insert(make_pair(3,30));printMap(m);}int main() {test01();system("pause");return0;}。
c++ map排序方法

c++ map排序方法【原创实用版3篇】目录(篇1)1.C++ map 简介2.C++ map 的排序方法2.1 自动排序2.2 手动排序正文(篇1)【C++ map 简介】C++中的 map 是 STL(标准模板库)中的一个容器,它是一个关联容器,用于存储键值对(key-value pair)。
map 中的元素按照键的顺序排列,可以自动排序,也可以手动排序。
map 提供了很多方便的操作,如插入、删除、查找等。
【C++ map 的排序方法】C++ map 默认情况下会按照键的升序对元素进行排序。
这种排序方式称为自动排序。
自动排序:当向 map 中插入新的元素时,map 会自动按照键的升序对元素进行排序。
如果需要按照降序排序,可以使用 map 的 rbegin 和rend 方法。
手动排序:如果需要对现有的 map 元素进行排序,可以使用以下方法:1.使用 sort() 函数:sort() 函数是 C++ STL 中的一个通用排序函数,可以对任何支持比较操作的对象进行排序。
使用 sort() 函数对map 进行排序时,需要先创建一个 vector,将 map 的元素复制到vector 中,然后对 vector 进行排序,最后将 vector 中的元素重新插入到 map 中。
2.使用 stable_sort() 函数:stable_sort() 函数是 C++ STL 中的一个稳定排序函数,适用于对 map 进行排序。
与 sort() 函数类似,使用 stable_sort() 函数对 map 进行排序时,需要先创建一个 vector,将 map 的元素复制到 vector 中,然后对 vector 进行排序,最后将vector 中的元素重新插入到 map 中。
3.使用 custom compare function:如果需要自定义排序规则,可以使用 custom compare function。
自定义比较函数需要满足一一对应关系(即对于任意的 x 和 y,如果 x < y,则 compare(x, y) < 0)。
map的用法总结大全

map的用法总结大全(学习版)编制人:__________________审核人:__________________审批人:__________________编制学校:__________________编制时间:____年____月____日序言下载提示:该文档是本店铺精心编制而成的,希望大家下载后,能够帮助大家解决实际问题。
文档下载后可定制修改,请根据实际需要进行调整和使用,谢谢!并且,本店铺为大家提供各种类型的经典范文,如英语单词、英语语法、英语听力、英语知识点、语文知识点、文言文、数学公式、数学知识点、作文大全、其他资料等等,想了解不同范文格式和写法,敬请关注!Download tips: This document is carefully compiled by this editor.I hope that after you download it, it can help you solve practical problems. The document can be customized and modified after downloading, please adjust and use it according to actual needs, thank you!In addition, this shop provides various types of classic sample essays, such as English words, English grammar, English listening, English knowledge points, Chinese knowledge points, classical Chinese, mathematical formulas, mathematics knowledge points, composition books, other materials, etc. Learn about the different formats and writing styles of sample essays, so stay tuned!map的用法总结大全map的意思n. 地图,天体图,类似地图的事物,〈美俚〉脸,面孔,(染色体上基因排列的)遗传图vt. 绘制(一地区等的)地图,勘查,详细规划,[遗传学]比对变形:过去式: mapped;现在分词:mapping;过去分词:mapped;map用法map可以用作名词map用作名词的基本意思是“地图”,特指“地球表面或一陆地的图”,表示某些地方的地理位置、形状、大小等,还可作“天体图”解,是可数名词。
std::map用法

std::map⽤法STL是标准C++系统的⼀组模板类,使⽤STL模板类最⼤的好处就是在各种C++编译器上都通⽤。
在STL模板类中,⽤于线性数据存储管理的类主要有vector, list, map 等等。
本⽂主要针对map对象,结合⾃⼰学习该对象的过程,讲解⼀下具体⽤法。
本⼈初学,⽔平有限,讲解差错之处,请⼤家多多批评指正。
map对象所实现的功能跟MFC得CMap相似,但是根据⼀些⽂章的介绍和论述,MFC CMap在个⽅⾯都与STL map有⼀定的差距,例如不是C++标准,不⽀持赋值构造,对象化概念不清晰等等。
使⽤map对象⾸先要包括头⽂件,包含语句中必须加⼊如下包含声明#include <map>注意,STL头⽂件没有扩展名.h包括头⽂件后就可以定义和使⽤map对象了,map对象是模板类,需要关键字和存储对象两个模板参数,例如:std:map<int, CString> enumMap;这样就定义了⼀个⽤int作为关键字检索CString条⽬的map对象,std表⽰命名空间,map对象在std名字空间中,为了⽅便,在这⾥我仍然使⽤了CString类,其实应该使⽤标准C++的std::string类,我们对模板类进⾏⼀下类型定义,这样⽤的⽅便,当然,不定义也可以,代码如下:typedef std:map<int, CString> UDT_MAP_INT_CSTRING;UDT_MAP_INT_CSTRING enumMap;如此map对象就定义好了,增加,改变map中的条⽬⾮常简单,因为map类已经对[]操作符进⾏了重载,代码如下:enumMap[1] = "One";enumMap[2] = "Two";.....enumMap[1] = "One Edit";或者insert⽅法enumMap.insert(make_pair(1,"One"));返回map中⽬前存储条⽬的总数⽤size()⽅法:int nSize = enumMap.size();查找map中是否包含某个关键字条⽬⽤find⽅法,传⼊的参数是要查找的key,在我们的例⼦⾥,是⼀个int数据,map中的条⽬数据是顺序存储的,被称作为⼀个sequence,在这⾥需要提到的是begin()和end()两个成员,分别代表map对象中第⼀个条⽬和最后⼀个条⽬,这两个数据的类型是iterator,iterator被定义为map中条⽬的类型,查找是否包含某个条⽬的代码如下:int nFindKey = 2; //要查找的KeyUDT_MAP_INT_CSTRING::iterator it; //定义⼀个条⽬变量(实际是指针)it = enumMap.find(nFindKey);if(it == enumMap.end()) {//没找到}else {//找到}//find的时候注意key的数据类型,最好⽤CString之类的能消除数据类型差异的key,否则可能会出现强制转换后仍找不到的情况。
C++ STL模板和Map使用大全

C++ STL模板和Map使用大全C++map的基本操作和使用(2009-09-23 14:58:21)分类:nguages标签:cmap编程基本操作livehaiitMap是c++的一个标准容器,她提供了很好一对一的关系,在一些程序中建立一个map可以起到事半功倍的效果,总结了一些map基本简单实用的操作!1. map最基本的构造函数;map<string , int >mapstring; map<int ,string >mapint;map<sring, char>mapstring; map< char ,string>mapchar;map<char ,int>mapchar; map<int ,char >mapint;2. map添加数据;map<int ,string> maplive;1.maplive.insert(pair<int,string>(102,"aclive"));2.maplive.insert(map<int,string>::value_type(321,"hai"));3, maplive[112]="April";//map中最简单最常用的插入添加!3,map中元素的查找:find()函数返回一个迭代器指向键值为key的元素,如果没找到就返回指向map尾部的迭代器。
map<int ,string >::iterator l_it;;l_it=maplive.find(112);if(l_it==maplive.end())cout<<"we do not find 112"<<endl;else cout<<"wo find 112"<<endl;4,map中元素的删除:如果删除112;map<int ,string >::iterator l_it;;l_it=maplive.find(112);if(l_it==maplive.end())cout<<"we do not find 112"<<endl;else maplive.erase(l_it); //delete 112;5,map中swap的用法:Map中的swap不是一个容器中的元素交换,而是两个容器交换; For example:#include <map>#include <iostream>using namespace std;int main( ){map <int, int> m1, m2, m3;map <int, int>::iterator m1_Iter;m1.insert ( pair <int, int> ( 1, 10 ) );m1.insert ( pair <int, int> ( 2, 20 ) );m1.insert ( pair <int, int> ( 3, 30 ) );m2.insert ( pair <int, int> ( 10, 100 ) );m2.insert ( pair <int, int> ( 20, 200 ) );m3.insert ( pair <int, int> ( 30, 300 ) );cout << "The original map m1 is:";for ( m1_Iter = m1.begin( ); m1_Iter != m1.end( ); m1_Iter++ )cout << " " << m1_Iter->second;cout << "." << endl;// This is the member function version of swap//m2 is said to be the argument map; m1 the target mapm1.swap( m2 );cout << "After swapping with m2, map m1 is:";for ( m1_Iter = m1.begin( ); m1_Iter != m1.end( ); m1_Iter++ )cout << " " << m1_Iter -> second;cout << "." << endl;cout << "After swapping with m2, map m2 is:";for ( m1_Iter = m2.begin( ); m1_Iter != m2.end( ); m1_Iter++ )cout << " " << m1_Iter -> second;cout << "." << endl;// This is the specialized template version of swapswap( m1, m3 );cout << "After swapping with m3, map m1 is:";for ( m1_Iter = m1.begin( ); m1_Iter != m1.end( ); m1_Iter++ )cout << " " << m1_Iter -> second;cout << "." << endl;}6.map的sort问题:Map中的元素是自动按key升序排序,所以不能对map用sort函数:For example:#include <map>#include <iostream>using namespace std;int main( ){map <int, int> m1;map <int, int>::iterator m1_Iter;m1.insert ( pair <int, int> ( 1, 20 ) );m1.insert ( pair <int, int> ( 4, 40 ) );m1.insert ( pair <int, int> ( 3, 60 ) );m1.insert ( pair <int, int> ( 2, 50 ) );m1.insert ( pair <int, int> ( 6, 40 ) );m1.insert ( pair <int, int> ( 7, 30 ) );cout << "The original map m1 is:"<<endl;for ( m1_Iter = m1.begin( ); m1_Iter != m1.end( ); m1_Iter++ ) cout << m1_Iter->first<<" "<<m1_Iter->second<<endl;}The original map m1 is:1 202 503 604 406 407 30请按任意键继续. . .7, map的基本操作函数:C++ Maps是一种关联式容器,包含“关键字/值”对begin() 返回指向map头部的迭代器clear()删除所有元素count() 返回指定元素出现的次数empty() 如果map为空则返回trueend() 返回指向map末尾的迭代器equal_range() 返回特殊条目的迭代器对erase() 删除一个元素find() 查找一个元素get_allocator() 返回map的配置器insert() 插入元素key_comp() 返回比较元素key的函数lower_bound() 返回键值>=给定元素的第一个位置max_size() 返回可以容纳的最大元素个数rbegin() 返回一个指向map尾部的逆向迭代器rend() 返回一个指向map头部的逆向迭代器size() 返回map中元素的个数swap() 交换两个mapupper_bound() 返回键值>给定元素的第一个位置value_comp() 返回比较元素value的函数C++map的基本操作和使用(2009-09-23 14:58:21)分类:nguages标签:cmap编程基本操作livehaiitMap是c++的一个标准容器,她提供了很好一对一的关系,在一些程序中建立一个map可以起到事半功倍的效果,总结了一些map基本简单实用的操作!1. map最基本的构造函数;map<string , int >mapstring; map<int ,string >mapint;map<sring, char>mapstring; map< char ,string>mapchar;map<char ,int>mapchar; map<int ,char >mapint;2. map添加数据;map<int ,string> maplive;1.maplive.insert(pair<int,string>(102,"aclive"));2.maplive.insert(map<int,string>::value_type(321,"hai"));3, maplive[112]="April";//map中最简单最常用的插入添加!3,map中元素的查找:find()函数返回一个迭代器指向键值为key的元素,如果没找到就返回指向map尾部的迭代器。
mapstl的用法 -回复

mapstl的用法-回复Mapstl是一个在线地图服务,可以帮助用户轻松创建、编辑和分享地图。
它是一个功能强大的工具,可以用于各种用途,如地理信息系统、旅游规划、地区分析等。
本文将详细介绍Mapstl的用法,并提供一步一步的回答,以帮助读者更好地利用这一工具。
一、访问Mapstl网站首先,在浏览器中打开Mapstl的官方网站。
你可以通过在搜索引擎中输入"Mapstl"来找到它。
点击进入官方网站后,你会看到一个简洁的界面,上面有一些基本操作和功能。
二、注册和登录账户如果你是第一次使用Mapstl,你需要先注册一个账户。
点击网页右上角的"注册"按钮,填写所需信息并创建一个新账户。
如果已经有账户,直接点击"登录",输入用户名和密码即可。
三、创建新地图登录后,你可以开始创建自己的地图。
首先,点击页面上方的"创建地图"按钮。
这将打开一个新的编辑页面,你可以在此页面上进行各种地图相关的操作。
四、地图基本信息设置在编辑页面上方,你可以看到一个"地图基本信息"的选项卡。
点击它,你可以设置地图的名称、描述、所在地区等基本信息。
这些信息将帮助其他用户更好地了解你的地图。
五、添加地图标记Mapstl的一个重要功能是添加地图标记。
你可以通过点击编辑页面上方的"添加标记"按钮,在地图上标记特定位置。
你可以选择标记的图标、添加备注以及设置标记的名称。
六、绘制路线和多边形除了地图标记,Mapstl还提供了绘制路线和多边形的功能。
点击编辑页面上方的"绘制线条"或"绘制多边形"按钮,你可以在地图上划定出特定的路线或区域。
这对于旅行规划或地区分析非常有用。
七、编辑地图样式Mapstl允许用户自定义地图的样式。
你可以选择不同的地图底图、调整地图的缩放级别,并根据需要更改地图的颜色、文字样式等。
stl中map的四种插入方法总结

stl中map的四种插⼊⽅法总结⽅法⼀:pair例:map<int, string> mp;mp.insert(pair<int,string>(1,"aaaaa"));⽅法⼆:make_pair例:map<int, string> mp;mp.insert(make_pair<int,string>(2,"bbbbb"));⽅法三:value_type例:map<int, string> mp;mp.insert(map<int, string>::value_type(3,"ccccc"));⽅法四:[]例:map<int, string> mp;mp[4] = "ddddd";四种⽅法异同:前三种⽅法当出现重复键时,编译器会报错,⽽第四种⽅法,当键重复时,会覆盖掉之前的键值对。
综合测试:#include<iostream>#include<map>using namespace std;int main(){map<int, string> mp;//map的插⼊⽅法有4种//insert返回值为pair 原型:typedef pair<iterator, bool> _Pairib//⽅法1.pair 在插⼊重复键的情况下前三种⽅法类似,这⾥只测试第⼀种pair<map<int,string>::iterator, bool> pair1 = mp.insert(pair<int,string>(1,"aaaaa11111"));if (pair1.second == true){cout<< "插⼊成功" <<endl;}else{cout<< "插⼊失败" <<endl;}pair<map<int,string>::iterator, bool> pair2 = mp.insert(pair<int,string>(1,"aaaaa22222"));if (pair2.second == true){cout<< "插⼊成功" <<endl;}else{cout<< "插⼊失败" <<endl;}//⽅法2.make_pairmp.insert(make_pair<int,string>(3,"bbbbb33333"));mp.insert(make_pair<int,string>(4,"bbbbb44444"));//⽅法3.value_typemp.insert(map<int, string>::value_type(5,"ccccc55555"));mp.insert(map<int, string>::value_type(6,"ccccc66666"));//⽅法4.[]mp[7] = "ddddd77777";mp[7] = "ddddd88888";for (map<int,string>::iterator it = mp.begin(); it != mp.end(); it++){cout<< it->first << "\t" << it->second <<endl;}cout<< "--------------------------------" <<endl;//删除while(!mp.empty()){map<int,string>::iterator it = mp.begin();cout<< it->first << "\t" << it->second <<endl; mp.erase(it);}return0;}。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
文档声明:
以下资料均属于本人在学习过程中产出的学习笔记,如果错误或者遗漏之处,请多多指正。
并且该文档在后期会随着学习的深入不断补充完善。
资料仅供学习交流使用。
作者:Aliven888
1、简述
a. 映射通常实现为二进制搜索树。
b. 映射是关联的容器,存储按特定顺序由键值和映射值的组合形成的元素。
c. 可以使用方括号运算符((operator [])通过其对应的键直接访问映射中的映射值
d. 在映射中,键值通常用于对元素进行排序和唯一标识,而映射值存储与该键关联的内容。
e. 键和映射值的类型可能有所不同,并以成员类型value_type分组在一起,成员类型value_type是将两者结合的对类型。
2、接口函数
2.1、迭代器(Iterators)
2.2、容量(Capacity)
2.3、元素访问(Element access)
2.4、操作(Operations)
2.5、修改(Modifiers)
3、接口函数使用演示3.1、定义一个变量:
3.2、迭代器(Iterators)
3.3、容量(Capacity)
3.4、访问元素(Element access)
3.5、操作(Operations)
3.6、修改(Modifiers)。