您当前的位置: 首页 >  json

qianbo_insist

暂无认证

  • 0浏览

    0关注

    399博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

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

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

注意文件格式

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             
关注
打赏
1663161521
查看更多评论
0.0391s