#include "boost/property_tree/xml_parser.hpp"
#include "boost/property_tree/ptree_fwd.hpp"
#include <string>
using namespace std;
read_xml(config_path_,pt_all);
string str=pt_all.get<string>(config_node);
return str;
read_xml(config_path_,pt_all);
int int_=pt_all.get<int>(config_node);
return int_;
编译:
g++ main.cpp -lboost_system
#include "boost/property_tree/ptree_fwd.hpp"
#include <string>
using namespace std;
using namespace boost::property_tree;
const string config_path="./config.xml"
string read_string(string config_node){
ptree pt_all;read_xml(config_path_,pt_all);
string str=pt_all.get<string>(config_node);
return str;
}
int read_int(string config_node){
ptree pt_all;read_xml(config_path_,pt_all);
int int_=pt_all.get<int>(config_node);
return int_;
}
int main(){
cout<<read_string("config.mysql.ip"<<endl;
cout<<read_string("config.mysql.port"<<endl;
}
---------------------------------------------------------
config.xml
<config>
<mysql>
<ip>192.168.1.1</ip>
<port>3306</port>
</mysql>
</config>
编译:
g++ main.cpp -lboost_system