Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 查找配对的匹配密钥范围_C++_Dictionary - Fatal编程技术网

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.second
map::lower\u bound
map::upper\u bound
可能会有所帮助。您好,感谢您尝试回答这个问题,您能简要解释一下您的解决方案如何解决OP的问题吗?