注意文件格式
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
关注
打赏