遍历以向量和映射作为其第二个节点的映射,并在第二个节点的第二个元素中找到匹配项。C++
Traverse a Map that has a vector and a Map as its second Node and find a match in the second Node's second element. C++
如何遍历第二个映射的第二个节点并找到重复项?使用下面的代码,我期望第二个for循环迭代4次,因为在外部映射中有4个节点。然而,在第二个for循环的第一次迭代之后,我得到了一个段错误。和想法吗?
void xmlParser::SortAndGroupByKey()
{
bool match = true;
std::map<std::vector<unsigned char>, std::vector<unsigned char>> tempMidNonceMap;
std::map<std::vector<unsigned char>, std::vector<unsigned char>>::iterator keyIt= m_mapMidNonceKey.begin()->second.begin();
//Iterate thru the second maps second element
for(std::map<std::vector<unsigned char>, std::map<std::vector<unsigned char>, std::vector<unsigned char>>>::iterator mapIt=m_mapMidNonceKey.begin(); mapIt != m_mapMidNonceKey.end(); ++mapIt)
{
//innerMapit points to the inner(2nd Map) map iterator
for(std::map<std::vector<unsigned char>, std::vector<unsigned char>>::iterator innerMapit= mapIt->second.begin(); innerMapit != mapIt->second.end(); ++innerMapit)
{
for(size_t i = 0; i < innerMapit->second.size(); ++i)
{
if(innerMapit->second[i] != keyIt->second[i]) //Do they match?
{
match = false;
break;
}
}
if(match)
{
//Make a pair of the values
tempMidNonceMap.insert(std::make_pair(mapIt->first,innerMapit->first));
}
}
//Check to see if the key already exists in the map if it does then only insert
if(!DuplicateKeyExists(keyIt->second))
{
this->m_mapKey.insert(std::make_pair(keyIt->second, tempMidNonceMap));
}
tempMidNonceMap.clear();
keyIt++;
match = true;
}
}
已解决:Map的Map不是我"认为"要填充的格式。
可能存在越界访问
innerMapit->second[i] != keyIt->second[i]
对于keyIt->second[i]
const bool match = (innerMapit->second != keyIt->second);
不是for(size_t i = 0; i < innerMapit->second.size(); ++i)
{
if(innerMapit->second[i] != keyIt->second[i]) //Do they match?
{
match = false;
break;
}
}
相关文章:
- 我有两个类需要在同一 cpp 文件中相互引用,但第一个类无法识别第二个类类型的对象
- 等待整个 omp 块完成,然后再调用第二个函数
- 我想在C++中读取一些多个字符,但它永远不会读取第二个字符
- 如何在创建自定义迭代器时获得 std::p air 的第一个和第二个?
- WinAPI 在单击第一个对话框上的按钮控件并销毁第一个对话框后创建第二个对话框
- 如何使用发送数据包所花费的时间计算两个节点之间的距离?
- 为什么我的双向链表删除函数会删除多个节点?
- 将第二个 GATT 服务添加到 Movesense 容器
- 如何在 c++ 中根据第二个元素按降序对列表进行排序
- 对的排序向量 (std::vector<pair<int, int>>) 按对的第一个元素搜索并更新第二个元素值
- 检查两个节点在子节点上是否具有相同状态的更优雅的方法
- 比较两个节点坐标的最佳方法是什么?
- 比较 2 个向量并从第二个向量中删除在第一个 - c++ 中找不到的元素
- 为什么这个程序没有打印返回的迭代器的正确第二个元素?
- 使第二个类的构造函数成为第一个类中的友元函数
- 为什么第二个代码给出了预期的结果,而第一个代码却没有?
- c++:尝试从链表中的第二个节点(虚拟节点)开始打印时出错
- 遍历以向量和映射作为其第二个节点的映射,并在第二个节点的第二个元素中找到匹配项。C++
- 解析第二个节点上嵌套的yml文件
- 在第三次调用中,当地址因本地作用域而被销毁时,temp2->next 如何能够访问第二个节点的地址?