gpt4 book ai didi

c++ - 错误 : no match for operator= in map c++

转载 作者:行者123 更新时间:2023-11-28 07:33:30 39 4
gpt4 key购买 nike

我正在尝试从 XML 文件导入数据并将它们保存在 5D map 中

// declaration of the map
map<char *, map<char *, map<char*, map<char *, map<char*, map<char*, char*, cmp_str>, cmp_str>, cmp_str>, cmp_str>, cmp_str>, cmp_str> XmlData;

我正在使用 RapidXML 解析器进行 XML 解析

file<> xmlFile("jobs.xml");
xml_document<> doc;
doc.parse<0>(xmlFile.data());

xml_node<> *node = doc.first_node();
while(node != 0) {
xml_node<> *child = node->first_node();
while (child != 0)
{
xml_node<> *subchild = child->first_node();
while (subchild != 0)
{
xml_node<> *subsubchild = subchild->first_node();
while (subsubchild != 0)
{
xml_node<> *subsubsubchild = subchild->first_node();
while (subsubsubchild != 0)
{
// the error appears here
XmlData[node->name()][child->name()][subchild->name()][subsubchild->name()][subsubsubchild->name()] = subsubsubchild->value();
subsubsubchild = subsubsubchild->next_sibling();
}
subsubchild = subsubchild->next_sibling();
}
subchild = subchild->next_sibling();
}
child = child->next_sibling();
}
node = node->next_sibling();
}

我不得不使用 5 个 while 循环来迭代所有节点

XML:

<Job>
<UserJob>
<RuleSet>
<def>
<Path>detection_c_new.dcp</Path>
<WkspName>MyWS</WkspName>
<UserName>Admin</UserName>
</def>
</RuleSet>
</UserJob>
<Scenes>
<Scene1>
<Info>
<def>
<ID>0</ID>
<Name>Scene 1</Name>
</def>
</Info>
<Layers>
<Layer1>
<Index>0</Index>
<Name>Layer 1</Name>
<ImgPath>CTX_MEM_Detail.jpg</ImgPath>
</Layer1>
</Layers>
<ExpItems>
<ExpItem1>
<Name>MyStats1</Name>
<Driver>CSV</Driver>
<Type>1</Type>
<Path>CTX_MEM_Detail.csv</Path>
</ExpItem1>
</ExpItems>
</Scene1>
</Scenes>
</Job>

在 CentOS 6 下使用 g++ 和 c++0x 进行编译时出现以下错误:

Job.cpp:133: error: no match for âoperator=â in â((std::map<char*, std::map<char*, char*, cmp_str, std::allocator<std::pair<char* const, char*> > >, cmp_str, std::all$
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_map.h:251: note: candidates are: std::map<_Key, _Tp, _Compare, _Alloc>& std::map<_Key, _Tp, _Compa$
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_map.h:266: note: std::map<_Key, _Tp, _Compare, _Alloc>& std::map<_Key, _Tp, _Compa$
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_map.h:286: note: std::map<_Key, _Tp, _Compare, _Alloc>& std::map<_Key, _Tp, _Compa$

最佳答案

char* 作为映射键是一件糟糕的事情,也可能是值。

您可以使用 const char* 作为 key 绝对确保您将指针传递给稳定的东西,例如仅文字。

基准解决方案将使用字符串作为 key 和有效负载,我想您的问题也会消失。最可能的直接原因是您的值拒绝转换为 char*。

关于c++ - 错误 : no match for operator= in map c++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17192037/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com