我如何在 C++ 中使用 xml?

how can i use xml in c++?

我从 C++ 开始,我尝试在我的代码中使用 xml,这是我的源代码:

    CvFileStorage * fileStorage;
    fileStorage = cvOpenFileStorage( "facedata.xml", 0, CV_STORAGE_WRITE );                            
    string d="apple";
    char* s=new char();
    strcpy(s,d.c_str());
    cvWrite(fileStorage, "word", s);
    cvReleaseFileStorage( &fileStorage );
    fileStorage = cvOpenFileStorage( "facedata.xml", 0, CV_STORAGE_READ );
    s=cvReadStringByName(fileStorage, 0, "word",0);
    cout<<s<<endl;

但是s没有returnword的内容,我需要你的帮助。

再次请用opencv的c++api:

cv::FileStorage fs("facedata.xml", cv::FileStorage::WRITE);
fs << "word" << "apple";
fs.release();

cv::FileStorage fs2("facedata.xml", cv::FileStorage::READ);
string s;
fs2["word"] >> s;
fs2.release();