gpt4 book ai didi

c++ - rapidjson:从文件中读取文档的工作代码?

转载 作者:可可西里 更新时间:2023-11-01 18:02:26 27 4
gpt4 key购买 nike

我需要一个有效的 C++ 代码来使用 rapidjson 从文件中读取文档:https://code.google.com/p/rapidjson/

在 wiki 中它还没有记录,示例仅从 std::string 反序列化,我对模板没有深入的了解。

我将我的文档序列化为一个文本文件,这是我写的代码,但它没有编译:

#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);

编译错误状态:error: 'Document' is not a member of 'rapidjson'

我正在使用带有 mingw 和 rapidjson v 0.1 的 Qt 4.8.1(我已经尝试使用升级后的 v 0.11 但错误仍然存​​在)

最佳答案

#include <rapidjson/document.h>
#include <rapidjson/istreamwrapper.h>
#include <fstream>

using namespace rapidjson;
using namespace std;

ifstream ifs("test.json");
IStreamWrapper isw(ifs);
Document d;
d.ParseStream(isw);

请阅读 http://rapidjson.org/md_doc_stream.html 中的文档.

关于c++ - rapidjson:从文件中读取文档的工作代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18107079/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com