我正在尝试遍历 std::list 并将数据从 DLL 中的线程写入 xml。但是,如果我将更多对象字段转储到 XML 中,则不会创建我的 XML。下面是我的课程的详细信息以及我用来将数据写入 XML 的代码。
class MyClass{
private:
BSTR member1;
BSTR member2;
BSTR member3;
BSTR member4;
public:
MyClass();
~MyClass();
BSTR getMember1()
{
return member1;
}
BSTR getMember2()
{
return member2;
}
BSTR getMember3()
{
return member3;
}
BSTR getMember4()
{
return member4;
}
//Corresponding setters are also present
};
std::list<MyClass> myList;
std::list<MyClass>::iterator iterator;
ofstream outputFile;
outputFile.open("C:\\test.xml",ios::out);
outputFile << "<root>" << endl;
for(iterator=myList.begin();iterator != myList.end();++iterator)
{
//Not working if more values are dumped
USES_CONVERSION;
outputFile << "<Object>" << endl;
outputFile << "<Member1>" << W2A(CString((*iterator).getMember1())) << "</Member1>" << endl;
outputFile << "<Member2>" << W2A(CString((*iterator).getMember2())) << "</Member2>" << endl;
outputFile << "<Member3>" << W2A(CString((*iterator).getMember3())) << "</Member3>" << endl;
outputFile << "<Member4>" << W2A(CString((*iterator).getMember4())) << "</Member4>" << endl;
outputFile << "</Object>" << endl;
}
outputFile << "</root>";
outpuFile.close();
有人可以帮我吗?