编译时出现以下错误,这是代码中的问题部分。请帮我理解错误是什么?
for (std::vector<std::string>::iterator i = files.begin(), end = files.end(); i != end; ++i)
{
printf("%s%s\n", parm.c_str(), i->c_str());
TiXmlElement *fileElement = new TiXmlElement("File");
fileElement->SetAttribute("name", *i); // error C2664
parentElement->LinkEndChild(fileElement);
}
files.clear();
for (std::vector<std::string>::iterator i = subFolders.begin(), end = subFolders.end(); i != end; ++i)
{
printf("%s%s\n", parm.c_str(), i->c_str());
TiXmlElement *fileElement = new TiXmlElement("Folder");
folderElement->SetAttribute("name", *i); //error C2227
parentElement->LinkEndChild(folderElement);
PrintDir(parm + *i + "\\", folderElement);
}
错误C2664 :void TiXmlElement :: SetAttribute(const char *,const char *):无法从&#39; std :: basic_string&lt; _Elem,_Traits,_Ax&gt;&#转换参数2 39; to&#39; const char *&#39 ;; 错误c2065 folderElement未声明的标识符; 错误C2227 左边的&#39; - &gt; SetAttribute&#39;必须指向class / struct / union;
答案 0 :(得分:0)
首先,在你的第二个for循环中,folderElement是未声明的。我认为你的意思是将其命名为folderElement而不是fileElement。所以改变这一行:
TiXmlElement *fileElement = new TiXmlElement("Folder");
到
TiXmlElement *folderElement = new TiXmlElement("Folder");