我想通过 stdio 为 RapidXML 读取文件。我使用了以下内容:
#include <iostream>
#include <rapidxml.hpp>
#include <stdio.h>
#include <Windows.h>
using namespace rapidxml;
int main(int argc, char** argv)
{
FILE *pFile;
pFile = fopen("D:\\ColladaFiles\\sample1.dae", "rb");
long lSize;
char *buffer;
size_t result;
//if error
if (pFile == NULL) { fputs("File error", stderr); exit(1); }
// obtain file size:
fseek(pFile, 0, SEEK_END);
lSize = ftell(pFile);
rewind(pFile);
// allocate memory to contain the whole file:
buffer = (char*)malloc(sizeof(char)*lSize);
if (buffer == NULL) { fputs("Memory error", stderr); exit(2); }
// copy the file into the buffer:
result = fread(buffer, 1, lSize, pFile);
if (result != lSize) { fputs("Reading error", stderr); exit(3); }
/* the whole file is now loaded in the memory buffer. */
xml_document<> xdoc;
xdoc.parse<0>(buffer);
system("pause");
return 0;
}
RapidXML 生成错误。因为如果我写以下缓冲区:
std::cout << buffer << std::endl;
最后一行包含以下内容: 如何快速读取 RapidXML 文件?