错误:在map c++中没有匹配operator=
error: no match for operator= in map c++
我试图从XML文件导入数据并将它们保存在5D地图中
// 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;
用于xml解析的RapidXML解析器
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下使用c++与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*作为键,绝对确保您将指针传递给稳定的对象,例如仅传递字面量。
基线解决方案将使用字符串作为密钥和有效载荷,我猜你的问题也会消失。最可能的直接原因是您的值拒绝转换为char*。
相关文章:
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- 使用一个考虑到std::map中键值的滚动或换行的键
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 允许从 std::map 的密钥窃取资源?
- 为什么 std::optional::operator=(U&&) 要求你是非标量类型?
- 'operator='已弃用:改用 QDir::setPath()
- 使用 operator[] 访问私有 std::map of unique_ptr
- 当 map 是一个整数数组并且由 operator[] 创建时,它是否初始化其映射类型
- 错误:与'operator='不匹配(操作数类型为"std::map<int、double>::iterator
- 为什么 vector::operator[] 的实现方式与 map::operator[] 不同?
- 为什么 map::operator[] 在设计上很慢
- 填充 std::map 时"C2593: operator = is ambiguous"
- Netbeans在使用c++std::map::operator[]时遇到一些问题
- std::map::operator[]违规访问windows上的内存
- 为什么C++ std::map::operator[] 不使用就地新?
- 错误:在map c++中没有匹配operator=
- 如何在初始化列表中使用std::map::operator=
- c++ STL map::operator[]在被删除的项上执行
- 可以依赖std::map::operator[]来触摸吗?