map

来源:互联网 发布:郑州淘宝加盟宣判了吗 编辑:程序博客网 时间:2024/05/18 03:02
1map的构造map  <string, int> mp;map<int ,string> mp;map<char,int> mp;第一个参数为关键字,不能相同。然后这个map自己本身是有序的,按照第一个关键字升序排列2.插入第一种:mp.insert(pair<string,int>("student",2));mp.insert(pair<string,int>("student",3));//用insert,但是如果map中出现了student 关键字的话,第二条就插不进去,此时mp[student]=2;第二种:mp["student"]=2;mp["student"]=3;//用数组来,然后就是直接覆盖了,此时  mp[student]=3     3. map <string, int> ::iterator it;    for(it=mc1.begin();it!=mc1.end();it++)      ans+=it->second;  如果是第一关键字的话,就是 it->first; 4.数据的查找 mp.count("student");//如果有的话,就返回1,没有的话就返回0 mp.find("student");//返回迭代器,出现的位置   5.map的清空
0 0
原创粉丝点击