时间:2022-07-28 11:01:57 | 栏目:JAVA代码 | 点击:次
map<string, int> m1; m1["def"] = 2;
map<string, int> m2; m2.insert({ "abc", 1 }); //使用这种就可以了 //其他形式和方式 m2.insert(make_pair(string("def"), 2)); m2.insert(pair<string, int>(string("ghi"), 3)); map<int, string> mapStudent; mapStudent.insert(map<int, string>::value_type (1,"student_one"));
map<string,int> m3 = { {"string",1}, {"sec",2}, {"trd",3} }; map<string,string> m4 = { {"first","second"}, {"third","fourth"}, {"fifth","sixth"}, {"begin","end"} };
map<string,int> a; //a是string到int的空map a["new"]; //"new"是新增的key
value类型为数型,即使像上面一样没有进行赋值操作,也一般会默认赋值为0。value是string或char类型,则默认为空。