Boost学习笔记(四)---利用boost::property_tree;读写xml文件,保存文件
来源:互联网 发布:二手房数据 编辑:程序博客网 时间:2024/05/16 05:53
定义xml文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<conf>
<gui>96</gui>
<theme>小青峰jd</theme>
<urls>
<url>http://blog.csdn.net/jiangdong2007</url>
<url>http://www.ur22.com</url><
url>http://www.ur33.com</url>
</urls>
<clock_style>24</clock_style><
/conf>
#include <iostream>
#include <string>#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
using namespace std;
using namespace boost;
int main(int argc, _TCHAR* argv[])
{
using namespace boost::property_tree;
ptree pt;
read_xml("D:\\test.xml",pt); //文件路径一定要正确,否则程序报错
cout<<pt.get<string>("conf.theme")<<endl; //读出文件内容
cout<<pt.get<int>("conf.clock_style")<<endl;
cout<<pt.get<long>("conf.gui")<<endl;
cout<<pt.get("conf.no_prop",100)<<endl; //没有返回100
BOOST_AUTO(child,pt.get_child("conf.urls"));
for (BOOST_AUTO(pos,child.begin()); pos!= child.end(); ++pos)
{
cout<<pos->second.data()<<"\t";
}
cout<<endl;
pt.put("conf.theme","小青峰jd");//修改
//write_xml(cout,pt); //写入到流
write_xml("d:\\test.xml",pt); //写入到文件
cout<<endl;
//system("pause");
return EXIT_SUCCESS;
}
0 0
- Boost学习笔记(四)---利用boost::property_tree;读写xml文件,保存文件
- 使用boost::property_tree::ptree读写ini文件
- boost库之property_tree解析xml文件
- boost::property_tree读取解析.xml文件
- boost库用property_tree读xml文件
- boost 之property_tree操作xml文件
- boost 读写 XML 文件
- boost property_tree 解析json文件
- 基于boost简单读写xml文件笔记
- boost::property_tree读取解析ini文件
- BOOST之property_tree对XML修改和保存
- 使用boost库读写XML文件
- boost使用property_tree操作xml
- boost::property_tree
- boost::property_tree
- boost::property_tree
- boost::property_tree
- boost.property_tree
- SPFA算法之最短路。
- 每日总结
- BCM芯片FP原理及相关SDK数据结构介绍
- Unity里Inspector面板自定义学习——Custom Data,序列化一个类,自定义 property drawer
- 基于Eclipse的Hadoop应用开发环境配置
- Boost学习笔记(四)---利用boost::property_tree;读写xml文件,保存文件
- c#控制台substring学习心得
- 算法时间复杂度-常数阶
- ZJUT1291(浮点A+B)
- MapReduce中实现对HBase中表的操作二
- Java面向对象——IO流 总结应用(打印流)
- quartz任务并行
- 操作格子 线段树
- 异或运算的一些知识