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

编程入门 行业动态 更新时间:2024-10-11 05:28:12
本文介绍了rapidjson:从文件中读取文档的工作代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要一个有效的c ++代码,以便使用rapidjson从文件中读取文档: code.google / p / rapidjson /

I need a working c++ code for reading document from file using rapidjson: code.google/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:从文件中读取文档的工作代码?

本文发布于:2023-11-28 16:24:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643118.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   文档   文件   工作   rapidjson

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!