map初始化的两种方法

来源:互联网 发布:大数据运维的原则 编辑:程序博客网 时间:2024/05/15 23:53

1 用普通的方法,同时赋值;
2 用pair类型

#include <iostream>  #include <map>  #include <string>  using namespace std;  int main()  {       map<string, int> map1;       map1[string("tttt")] = 1;       map1[string("ggg")] = 2;       map1.insert(pair<string, int>("niubi", 3));       map<string, int>::iterator it = map1.begin();       while ( it != map1.end())       {           cout<<it->first<<" "<<it->second<<endl;        it++;       }       system("pause");       return 0;  }  
1 0