map<string,string>在c99中怎么初始化,或者说怎么赋值?
1个回答
展开全部
map<string,string> mymap;
// 添加元素
mymap.insert(pair<string,string>("haha","hehe"));
mymap.insert(map<string,string>::value_type("haha","hehe"));
mymap["haha"] = "hehe";
参考代码如下:
#include<iostream>
#include<map>
using namespace std;
int main()
{
typedef map<string,string>::iterator m_itor;
map<string,string> mymap;
mymap["223"] = "adflijd";
mymap.insert(pair<string,string>("235dadf","sdflisha"));
mymap.insert(map<string,string>::value_type("dlfkja","ajefoi"));
for(m_itor it = mymap.begin(); it != mymap.end(); it++)
cout<<it->first<<" "<<it->second<<endl;
return 0;
}
运行结果如下:
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询