C++ 查找配对的匹配密钥范围
假设我有一张地图:C++ 查找配对的匹配密钥范围,c++,dictionary,C++,Dictionary,假设我有一张地图: std::map<std::pair<string,int>,int> map_example; std::map\u示例; 如何在映射中找到具有以下属性的键的所有元素:该对中的字符串为“a”,int值介于5和10之间(包括5和10)。或者,将我的地图制作成下面这样会更好吗 std::map<string,std::map<int,int> map_example2; std::map变量result将为您提供一个map,其中包
std::map<std::pair<string,int>,int> map_example;
std::map\u示例;
如何在映射中找到具有以下属性的键的所有元素:该对中的字符串为“a”,int值介于5和10之间(包括5和10)。或者,将我的地图制作成下面这样会更好吗
std::map<string,std::map<int,int> map_example2;
std::map变量result
将为您提供一个map
,其中包含map\u示例
中与您的条件匹配的所有元素:
decltype(map_example) result;
for (const auto& item : map_example) {
const auto& key = item.first;
if (key.first == "A" && key.second >= 5 && key.second <= 10)
result.insert(item);
}
decltype(map\u示例)结果;
用于(常量自动和项目:映射示例){
const auto&key=item.first;
如果(key.first==“A”&&key.second>=5&&key.secondmap::lower\u bound
和map::upper\u bound
可能会有所帮助。您好,感谢您尝试回答这个问题,您能简要解释一下您的解决方案如何解决OP的问题吗?