使用唯一类型键将地图插入其他地图 [英] Insert a map into other map with a unique type key

查看:60
本文介绍了使用唯一类型键将地图插入其他地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是C ++映射的新手,我对将特定类型的映射复制到另一张相同类型的映射有疑问,详细信息显示在
下面,我最初声明了这样的映射

hello guys i am new to maps in C++ i am having a question regarding copying a particular type map to another map of same kind the details are shown below I initially declared a map like this

map<string,int> objmap,obj_porcess ;
 for(int i = 0; i < 10]; i++) {
 obj_process[to_string(i)]=i+10//some processing the to_string is just in case but i have strings with names for all 10 values
 }

like

obj_process["today"]=1;
obj_process["yesterday"]=-1;
obj_process["tommorow"]=2;

现在我想定义这样的内容,只是我的关键词应该与流程一起添加obj_process中的所有键都可以相同

now i want to define some thing like this just my key word should be added with the process and remaining all can be same for all the keys from obj_process

objmap["process_"+"today"] = obj_process["today"];

而不是定义所有10个代码,我可以有一个简单的代码原因吗,在这里我举了10个示例,我想在地图键中设置200套不同的字符串

instead of defining all 10 can i have a simple code cause in here i took an example of 10 but i have like 200 set of different strings in the key of map

推荐答案

您可以遍历地图吗?

for(auto& i:obj_process)
objmap [ process + i.first] = i.second;

这篇关于使用唯一类型键将地图插入其他地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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