map<string,string>在c99中怎么初始化,或者说怎么赋值?

2025-04-26 20:44:16
推荐回答(1个)
回答1:

map mymap;
// 添加元素
mymap.insert(pair("haha","hehe"));
mymap.insert(map::value_type("haha","hehe"));
mymap["haha"] = "hehe";

参考代码如下:

#include
#include
using namespace std;
int main()
{
    typedef map::iterator m_itor;
    map mymap;
    mymap["223"] = "adflijd";
    mymap.insert(pair("235dadf","sdflisha"));
    mymap.insert(map::value_type("dlfkja","ajefoi"));

    for(m_itor it = mymap.begin(); it != mymap.end(); it++)
        cout<first<<" "<second<
    return 0;
}

运行结果如下: