关联容器,完全没用过,一直想用,FUC,本文只介绍初级使用方式,不能贪多
#include<iostream>
#include<map>
#include<set>
#include<string>
using namespace std;typedef pair<int,string> Auth;
int main()
{
map<int,string> m;
set<string> s;Auth p1,p2,p3,p4;
p1 = make_pair(1,"s");
p2 = make_pair(2,"y");
p3 = make_pair(3,"t");
p4 = make_pair(3,"z");
m.insert(p1);
m.insert(p2);
m.insert(p3);
cout<<m[3]<<endl;
map<int,string>::iterator it;
if( (it = m.find(3)) != m.end())
{
it->second = "z";
}else
{
m.insert(p4);
}
cout<<m[3]<<endl;
}
map set multimap multiset
pair:
typedef pair<string,string> Author; Author proust("abc","def");Author
joyce("dd","ee");
Author syt; syt = make_pair("ee","ff"); first,second,公有访问
map 类型
键可以自由定义一个若排序,但注意自己定义的小于不能出现环,并且不能修改
时间: 2024-12-28 15:25:04