对C++了解的不多,我的需求是往JSON文件里写入字符串,这种方式不需要用开源的库,直接写文件就可以。附上代码需要包含studio.h头文件以计fstream
long a=123456; char json[1024]={0}; printf("[{ "TXPerSecdata":"%ld"} ]",a); sprintf(json,"[{ "TXPerSecdata":"%ld"} ]",a); ofstream fos; fos.open("D:/test.json",ios::trunc | ios::binary | ios::out); fos<<json; fos.close(); return 0;
参考了这两篇
https://www.runoob.com/cprogramming/c-function-printf.html
https://blog.csdn.net/zenail501129/article/details/22991485?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase