部分匹配 std::map 的键
本文介绍了部分匹配 std::map 的键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 std::map
并且我想使用子字符串搜索键.例如,我有以下代码:
I have an std::map
and I want to search for a key using a substring. For example, I have the following code:
现在,如果Marla"存储在地图中,我想搜索包含子字符串Marl"而不是Marlon"的位置.我想找到以Marl"开头的东西.我最多需要找到一个位置.这可能吗?如果是这样,怎么做?
Now, I want to search for the position that holds the substring "Marl" and not "Marlon", if "Marla" is stored in the map. I want to find something that starts with "Marl". I need to find at most one position. Is this possible? If so, how?
我不想使用任何 Boost 库!
I don't want to use any Boost libraries!
推荐答案
你不能有效地搜索子字符串,但是你可以搜索prefix:
You can't efficiently search for substring, but you can for prefix:
打印出来:
这篇关于部分匹配 std::map 的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!