关联容器,完全没用过,一直想用,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 类型

键可以自由定义一个若排序,但注意自己定义的小于不能出现环,并且不能修改

相关文章:

  • 2021-11-11
  • 2021-09-24
  • 2021-09-29
  • 2021-07-27
  • 2022-01-27
  • 2021-08-10
  • 2021-06-18
  • 2021-08-08
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-03-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案