0

I got the following errors while compiling, here's the problem part of code. Please help me understand what's wrong?

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);

   } 

error C2664: void TiXmlElement::SetAttribute(const char *,const char *): cannot convert parameter 2 from 'std::basic_string<_Elem,_Traits,_Ax>' to 'const char *'; error c2065 folderElement undeclared identifier; error C2227 left of '->SetAttribute' must point to class/struct/union;

localhost
  • 375
  • 1
  • 3
  • 15

1 Answers1

0

For one thing, in your second for loop, folderElement is undeclared. I think you meant to name it folderElement instead of fileElement. So change this line:

TiXmlElement *fileElement = new TiXmlElement("Folder");

to

TiXmlElement *folderElement = new TiXmlElement("Folder");