当前位置:网站首页>rapidjson读写json文件
rapidjson读写json文件
2022-07-04 07:13:00 【面向对象】
#include "rapidjson/document.h"
#include "rapidjson/istreamwrapper.h"
#include "rapidjson/prettywriter.h"
#include "rapidjson/rapidjson.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/writer.h"
#include "rapidjson/filewritestream.h"
using namespace std;
using namespace rapidjson;
string readJsonfile(string path)
{
ifstream config_file(path);
if (!config_file.is_open())
{
return "json file not exist";
}
IStreamWrapper config(config_file);
Document doc;
doc.ParseStream(config);
StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
doc.Accept(writer);
config_file.close();
return buffer.GetString();
}
void writeToJsonFile(string &jsonstr, string filepath)
{
Document doc;
doc.Parse(jsonstr.c_str());
FILE* fp = fopen(filepath.c_str(), "wb");
char writeBuffer[65535];
FileWriteStream os(fp, writeBuffer, sizeof(writeBuffer));
PrettyWriter<FileWriteStream> writer(os);
doc.Accept(writer);
fclose(fp);
std::cout << "writeToJsonFile end" <<std::endl;
}边栏推荐
- [kubernetes series] kubesphere is installed on kubernetes
- 高薪程序员&面试题精讲系列119之Redis如何实现分布式锁?
- kubernetes集群之Label管理
- BasicVSR++: Improving Video Super-Resolutionwith Enhanced Propagation and Alignment
- 【FreeRTOS】FreeRTOS學習筆記(7)— 手寫FreeRTOS雙向鏈錶/源碼分析
- Two years ago, the United States was reluctant to sell chips, but now there are mountains of chips begging China for help
- If there are two sources in the same job, it will be reported that one of the databases cannot be found. Is there a boss to answer
- Chain ide -- the infrastructure of the metauniverse
- Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction
- ABCD four sequential execution methods, extended application
猜你喜欢

selenium IDE插件下载安装使用教程
![[kubernetes series] kubesphere is installed on kubernetes](/img/2b/eb39cf78b3bb9908b01f279e2f9958.png)
[kubernetes series] kubesphere is installed on kubernetes

Zabbix agent主动模式的实现

Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction

Cervical vertebra, beriberi
![[Mori city] random talk on GIS data (I)](/img/e4/2a2ceb10a2c0285cdd0c922f827930.png)
[Mori city] random talk on GIS data (I)

How notepad++ counts words

Responsive - media query

Introduction to spark core components

leetcode825. Age appropriate friends
随机推荐
Deep understanding of redis -- a new type of bitmap / hyperloglgo / Geo
Set JTAG fuc invalid to normal IO port
Tar source code analysis 6
Lottery system test report
There is no Chinese prompt below when inputting text in win10 Microsoft Pinyin input method
【FPGA教程案例7】基于verilog的计数器设计与实现
提升复杂场景三维重建精度 | 基于PaddleSeg分割无人机遥感影像
MySQL 45 lecture learning notes (XIII) delete half of the table data, and the table file size remains the same
Redis interview question set
leetcode825. Age appropriate friends
Su Weijie, a member of Qingyuan Association and an assistant professor at the University of Pennsylvania, won the first Siam Youth Award for data science, focusing on privacy data protection, etc
tornado项目之路由装饰器
flask-sqlalchemy 循环引用
Transition technology from IPv4 to IPv6
在已经知道表格列勾选一个显示一列
果果带你写链表,小学生看了都说好
centos8安装mysql.7 无法开机启动
由于dms升级为了新版,我之前的sql在老版本的dms中,这种情况下,如何找回我之前的sql呢?
Adaptive spatiotemporal fusion of multi-target networks for compressed video perception enhancement
抽奖系统测试报告