问题描述
我需要一个有效的c ++代码,以便使用rapidjson从文件中读取文档:
I need a working c++ code for reading document from file using rapidjson: https://code.google.com/p/rapidjson/
在维基中它还没有文档,例子只是从std :: string开始序列化,我没有深入的知识的模板。
In the wiki it's yet undocumented, the examples unserialize only from std::string, I haven't a deep knowledge of templates.
我将我的文档序列化成一个文本文件,这是我写的代码,但它不
compile:
I serialized my document into a text file and this is the code I wrote, but it doesn't compile:
#include "rapidjson/prettywriter.h" // for stringify JSON
#include "rapidjson/writer.h" // for stringify JSON
#include "rapidjson/filestream.h" // wrapper of C stream for prettywriter as output
[...]
std::ifstream myfile ("c:\\statdata.txt");
rapidjson::Document document;
document.ParseStream<0>(myfile);
编译错误状态:错误:'Document'不是'rapidjson'的成员
the compilation error state: error: 'Document' is not a member of 'rapidjson'
我使用Qt 4.8.1与mingw和rapidjson v 0.1(我已经尝试与升级v 0.11,但错误仍然)
I'm using Qt 4.8.1 with mingw and rapidjson v 0.1 (I already try with upgraded v 0.11 but the error remain)
推荐答案
FileStream 在@ Raanan的答案显然已弃用。在源代码中有一个注释,改为使用 FileReadStream
。
The FileStream
in @Raanan's answer is apparently deprecated. There's a comment in the source code that says to use FileReadStream
instead.
#include <rapidjson/document.h>
#include <rapidjson/filereadstream.h>
using namespace rapidjson;
// ...
FILE* pFile = fopen(fileName.c_str(), "rb");
char buffer[65536];
FileReadStream is(pFile, buffer, sizeof(buffer));
Document document;
document.ParseStream<0, UTF8<>, FileReadStream>(is);
这篇关于rapidjson:从文件中读取文档的工作代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!