我从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
未返回word
的内容,我需要您的帮助。
答案 0 :(得分:1)
再次,请使用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();