从3D地图插入和读取值 [英] Inserting and Reading Values from 3D Map

查看:176
本文介绍了从3D地图插入和读取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先我阅读所有以前提出的与这个问题相关的问题,但没能解决我的问题。我有一个3D地图,

First of all I read all the previously asked questions related to this questions, but didn't able to solve my problem. I have one 3D Map,

map<int,map<const char*, const char*>> map3D;
map<const char*, const char*> submap;

现在我插入的值是这样的,int的值的最大值是 5 ,但是对于每个int值,子地图都有 50键和值

Now i inserted valued in it like this, the max of value of int is 5 but for each int value there is 50 key and value for submap.

I inserted the value like this

I inserted the value like this

submap.insert(std::pair<const char*,const char*>(TempA, TempB));
map3D.insert(pair<int,map<const char*,const char*>>(count,submap));

计数值将在Temp1和TempB值超过50个值后递增。现在我想读回它的价值观,并且我这样做像这个问题中提到的如何循环访问c ++映射

count value will be incremented after Temp1 and TempB values will be more than 50 values. Now i want to read it back the values and for this i am doing like this as mentioned in this question How to loop through a c++ map.

std::map<int,map<const char*,const char*>>::iterator out_it;
    for(out_it =map3D.begin();out_it != map3D.end();++out_it)
    {
        for(std::map<const char*, const char*>::const_iterator in_it=out_it->second.begin();in_it != out_it->second.end(); ++in_it)
            std::cout << in_it->first << " => " << in_it->second <<endl;
}

由于int只有5,所以它只显示TempA和TempB的五个值。如果只在子映射中进行迭代,它将显示所有的值

As int is only 5 so it is showing only five values of TempA and TempB. If iterate only in submap, it is showing all the values

for(std::map<const char*, const char*>::const_iterator in_it=submap.begin();in_it != submap.end(); ++in_it)
                std::cout << in_it->first << " => " << in_it->second <<endl;

任何人都可以指导我如何读取所有的值。感谢

Can Anyone guide me how i can read all the values. Thanks

推荐答案

一切正常。因为你每次插入相同的子映射时都会编码:

Everything is correct. Because you code every time inserts the same submap:

submap.insert(std::pair<const char*,const char*>(TempA, TempB));
map3D.insert(pair<int,map<const char*,const char*>>(count,submap));

如果您需要包含所有值的子映射,因此您需要先填充子映射,然后插入map3D或使用指针到子映射。

If you need submap that contains all values, so you need fill your submap first and than insert into the map3D or use pointer to submap.

map<int,map<const char*, const char*>*> map3D;
map<const char*, const char*>* submap = new map<const char*, const char*>();
...
submap->insert(std::pair<const char*,const char*>(TempA, TempB));
map3D.insert(pair<int,map<const char*,const char*>*>(count,submap));

否则你需要在每次要插入到map3D时创建submap。

Otherwise your need to create submap each time when you want to insert into the map3D.

map<const char*, const char*> submap;
submap.insert(std::pair<const char*,const char*>(TempA, TempB));
map3D.insert(pair<int,map<const char*,const char*>>(count,submap));

这篇关于从3D地图插入和读取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆