您当前的位置: 首页 >  qianbo_insist json

c++如何使用json配置文件

qianbo_insist 发布时间:2021-07-12 17:17:14 ,浏览量:4

注意文件格式

c++读写文件格式最好是utf-8格式,很多读写json

定义自己的数据结构
typedef struct s_camera
{
	std::string name;
	std::string addr;
}s_camera;

数据结构定义好以后,就可以开始进行读写 使用c++ fstream 来读json文本文件,获取文本大小

	stream.seekg(0, ios::end);
	fsize = stream.tellg();
	stream.seekg(0, ios::beg);

原理就是定位到文件末尾,获取位置,再回到文件首,这样就知道自己需要的缓冲区的大小了。

show me the code
#include "json.hpp"
#include 
#include 
using json = nlohmann::json;


typedef struct s_camera
{
	std::string name;
	std::string addr;
}s_camera;

static string remove_n(const char * begin, size_t len)
{
	const char *pos = begin;
	const char *end = begin+len;
	string s;
	while (pos             
关注
打赏
1688896170
查看更多评论
0.1853s