如何在c++映射中提取具有相同前缀的记录
how to extract the records with same prefix in C++ map?
现在,我只知道在一个地图中有几个具有相同前缀"head_"的记录。如果我不知道它们在这个映射中的确切键,我如何提取所有这些记录?任何想法?
您必须遍历映射。但是,您可以通过调用std::map::lower_bound
,并使用key等于您想要的前缀来有效地找到起点。
void extract_keys(const std::map<std::string, int>& some_map){
auto iter = some_map.lower_bound("head_");
while (iter->first.find("head_") == 0){
//do things with key, value pair
++iter;
}
}
上面的代码应该可以工作,但是我承认我没有测试它。(任何错误都是可以修复的)
相关文章:
- 将两个数组中的差异记录在第三个数组中
- 编译器如何在前缀和 postix 运算符之间进行区分?
- 禁止在控制台上记录谷神星
- 创建 Spdlog 异步文件记录器时遇到困难
- fastrtps:如何在发布/订阅级别使用 DDS 历史记录?
- 查找带有 Anaconda cmake 前缀的 boost-python3
- 迭代器类的重载前缀增量运算符会引发分段错误
- 如何将自定义记录器与websocketpp一起使用?
- 如何在友元函数中使用静态成员而不添加前缀 [类名]::
- C++结构到德尔福记录dll调用
- 生成前缀位掩码
- 如何判断SSL_read是否已经接收并处理了来自单个消息的所有记录
- 定义宏以将前缀 0x 添加到十六进制字符串文本
- CMake 错误 - 目标 foo INTERFACE_SOURCES属性包含在源目录中以前缀为前缀的路径
- 如何在自定义对象的<<运算符中添加自定义前缀
- 如何实现具有多个平台__FILE__和__LINE__信息的 C/C++ 可变参数日志记录宏?
- 高效的字符串截断算法,按顺序删除相等的前缀和后缀
- 我是否可以使用 win32 句柄以编程方式记录发送到/接收到 USB/COM 的内容
- 以C++显示单词的所有前缀
- 如何在c++映射中提取具有相同前缀的记录