c++ - 获取与 map 中的查询匹配的所有键

标签 c++ stl dictionary

假设我在 map 中有多个具有相同值的键。那么在那种情况下,我如何检索与查询匹配的所有键。

或者,是否有可能告诉 find 操作在特定值之后进行搜索。
我正在使用 std::map,C++。

最佳答案

这样的事情对你有用吗:

void FindKeysWithValue(Value aValue, list<Key>& aList)
{
    aList.clear();

    for_each(iMap.begin(), iMap.end(), [&] (const pair<Key, Value>& aPair)
    {
        if (aPair.second == aValue)
        {
            aList.push_back(aPair.first);
        }
    });
}

关于c++ - 获取与 map 中的查询匹配的所有键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13202864/

相关文章:

android - std::map 链接器错误 ndk r8c with APP_STL := gnuSTL_static

C++ STL make_heap 和priority_queue 给出不同的输出

c++ - 如何编写STL IO 机械手函数风格的代码?

javascript - 开放层 6 : How to calculate the distance between two points (clickable) from api?

android - 如何更改 .map 文件中的 mapsforge 街道名称

c++ - 在调试期间获取 C++ 运行时类型?

c++ - boost::future 和 Continuations - 值已设置,但 future 仍然受阻

c++ - std::mutex 是否足以实现线程间的数据同步

c++ - 找不到 -lperl 在 C++ 上执行 makefile

c# ToDictionary with ContainsKey 检查