这个问题回答了如何用嵌套将数据写入XML文件:在OpenCV中创建XML文件
参考相同的问题(和可接受的答案),我如何使用FileStorage类读取相同的文件?简而言之,我如何读取下面代码段写入的数据?
FileStorage fs; // Open it and check that it is opened;
fs << "SimpleData" << 1;
fs << "Structure" << "{";
fs << "firstField" << 1;
fs << "secondField" << 2;
fs << "}"; // End of structure node
fs << "SimpleData2" << 2;
您可以使用:
FileStorage fs;
fs.open(filename, FileStorage::READ);
int SimpleData = (int) fs["SimpleData"];
FileNode n = fs["Structure"]; // Read Structure sequence - Get node
int firstField = (int)(n["firstField"]);
int secondField = (int)(n["secondField"]);
int SimpleData2 = (int) fs["SimpleData2"];
查看更多信息