C++ 配对内图-如何进行配对

C++ 配对内图-如何进行配对,c++,map,C++,Map,我有以下代码: typedef std::map<const char *, std::pair<const char *, const char *> > MyMap; MyMap the_map; the_map.insert(std::make_pair("Text1", std::make_pair("Text2", "Text3"))); typedef std::map MyMap; MyMap是_地图; 插入(std::make_pair(“Text1”

我有以下代码:

typedef std::map<const char *, std::pair<const char *, const char *> > MyMap;
MyMap the_map;

the_map.insert(std::make_pair("Text1", std::make_pair("Text2", "Text3")));
typedef std::map MyMap;
MyMap是_地图;
插入(std::make_pair(“Text1”,std::make_pair(“Text2”,“Text3”));
显然,目的是以这种方式存储信息:

“Text1”->“Text2”->“Text3”

问题:我如何处理第一个键(如“Text1”)的每个元素并更改每个内部键(如“Text3”)的值

谢谢。

A没有
begin()
end()
函数

您只需要一个循环:

for (const auto& it : the_map) {
        std::cout << it.first << " " << it.second.first 
                  << " " << it.second.second << std::endl;
}
for(const auto&it:the_map){

std::cout您可以使用映射的迭代器去抛出所有元素:

for (std::map<const char *, std::pair<const char *, const char *> >::iterator ii = the_map.begin(), e = the_map.end(); ii != e; ii++) {
    // ii.first  - key value
    // ii.second - stored value (in your case a pair)
    //
    // ii.second.first  - key value of pair stored in map under ii.first
    // ii.second.second - stored value of pair stored in map under ii.first
}
for(std::map::iterator ii=映射.begin(),e=映射.end();ii!=e;ii++){
//二、第一——关键值
//ii.秒-存储值(在您的情况下为一对)
//
//ii.second.first-存储在ii.first下映射中的对的键值
//ii.second.second-在ii.first下存储在map中的对的存储值
}

“NeStask”是固定的,谢谢。我使用了太老的GCC并得到这个错误信息:错误:ISO C++禁止声明“它”没有类型[-fPielix] @阿曼达VZZ提供了一个使用迭代器的答案,没有<代码> Audio/Cux>关键字。