欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來(lái)到入門教程網(wǎng)!

C語(yǔ)言

當(dāng)前位置:主頁(yè) > 軟件編程 > C語(yǔ)言 >

使用boost讀取XML文件詳細(xì)介紹

來(lái)源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C語(yǔ)言|點(diǎn)擊: 次

boost讀取XML文件

boost中提供了對(duì)配置文件讀取的支持,它就是:property_tree。

    basic_ptree 是property_tree的核心基礎(chǔ)。其接口像std::list??梢詧?zhí)行很多基本的元素操作,比如使用begin()、end()等。
    此外還加入了操作屬性樹(shù)的get()、get_child()、get_value()、data()等額外的操作。

    basic_ptree有兩個(gè)重要的內(nèi)部定義self_type和value_type。self_type是basic_ptree模板實(shí)例化后自身的類型,它也是子節(jié)點(diǎn)的類型。value_type是節(jié)點(diǎn)的數(shù)據(jù)結(jié)構(gòu),它是一個(gè)std::pair,它含有屬性名(first)和節(jié)點(diǎn)自身(second)。

    通常不使用basic_ptree,而是使用預(yù)定義的typedef。ptree、wptree、iptree、wiptree。前綴i表示忽略大小寫,前綴w表示支持寬字符。

例如:

config.xml

<?xml version="1.0" encoding="utf-8"?> 
<con> 
 <id>1</id> 
 <name>fansy</name> 
 <urls> 
  <url>http://blog.csdn.net//fansongy</url> 
  <url>http://weibo.com//fansongy</url> 
 </urls> 
</con>  

我要讀取它的數(shù)據(jù):



#include <iostream> 
#include <boost/property_tree/ptree.hpp> 
#include <boost/property_tree/xml_parser.hpp> 
#include <boost/typeof/typeof.hpp>  
using namespace std; 
using namespace boost::property_tree; 
int main() 
{ 
  ptree pt; 
  read_xml("conf.xml",pt);   //讀入一個(gè)xml文件 
  cout<<"ID is "<<pt.get<int>("con.id")<<endl; //讀取節(jié)點(diǎn)中的信息 
  cout<<"Try Default"<<pt.get<int>("con.no_prop",100)<<endl; //如果取不到,則使用默認(rèn)值 
  ptree child = pt.get_child("con");  //取一個(gè)子節(jié)點(diǎn) 
  cout<<"name is :"<<child.get<string>("name")<<endl;  //對(duì)子節(jié)點(diǎn)操作,其實(shí)跟上面的操作一樣 
   
  child = pt.get_child("con.urls"); 
  for(BOOST_AUTO(pos,child.begin());pos != child.end();++pos) //boost中的auto 
   { 
     cout<<"\t"+pos->second.data()<<endl; 
   } 
  pt.put("con.name","Sword");  //更改某個(gè)鍵值 
  pt.add("con.urls.url",http://www.baidu.com); //增加某個(gè)鍵值 
  write_xml("conf.xml",pt);  //寫入XML 
  getchar(); 
  return 0; 
} 



運(yùn)行的顯示為: 
ID is 1 
Try Default100 
name is :fansy 
    http://blog.csdn.net//fansongy 
    http://weibo.com//fansongy 



config.xml為: 
<?xml version="1.0" encoding="utf-8"?> 
<con> 
 <id>1</id> 
 <name>Sword</name> 
<urls> 
   <url>http://blog.csdn.net//fansongy</url> 
   <url>http://weibo.com//fansongy</url> 
   <url>http://www.baidu.com</url> 
</urls> 
</con>  



感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

上一篇:C++中的friend函數(shù)詳細(xì)解析

欄    目:C語(yǔ)言

下一篇:C++中vector容器的用法

本文標(biāo)題:使用boost讀取XML文件詳細(xì)介紹

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/1998.html

網(wǎng)頁(yè)制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語(yǔ)言數(shù)據(jù)庫(kù)服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有