首页 > Web开发 > 详细

boost生成json中的put操作

时间:2019-02-27 11:08:14      阅读:929      评论:0      收藏:0      [点我收藏+]

 

ptree中的put操作后可以加<>,指定类型,不加<>采用默认的类型,感觉不加反而更好用.用法见下面例子.

#include <iostream> #include <string> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/json_parser.hpp> using namespace std; using namespace boost::property_tree; int main() { ptree children; ptree child1; long long i = 2147483648; cout << i << endl; children.add_child("数字",child1.put<int>("", i));#put后面的<>可以指定值i的类型,例如此处指定i为int,当然这里指定int会导致溢出.不指定时,值i默认就是定义的类型long long. write_json("test2.json", children); return 0; }

相关知识:
boost property_tree解析json文件相关文档如下:json_parser basic_ptree(ptree是basic_ptree<string, string>的别名)

json_parser:
read_json(filename, ptree):用于将filename文件中的内容读入ptree结构中。
write_json(filename, ptree):用于将ptree结构中的内容写入filename中。
basic_ptree:
self_type& get_child(path_type):
get_value<>: 以某种格式获得某个元素的值.例子:https://blog.csdn.net/shyanyang/article/details/44203169

 

boost生成json中的put操作

原文:https://www.cnblogs.com/Stephen-Qin/p/10441381.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!