Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost property tree to string

Tags:

c++

boost

Need to transfer system configuration that is stored in ini file over internet. I'm using boost to deal with configuration ini file. How to save whole property tree to string?

like image 348
vico Avatar asked Dec 04 '14 10:12

vico


People also ask

How to use boost's property_tree?

To use boost::property_tree::ptree, include the header file boost/property_tree/ptree.hpp. This is a master header file, so no other header files need to be included. 1) An instance of type property tree is made and value (directory) is given to the instance. 2) Firstly in new ptree type variable is initialized with the value of child of "C".

How to write boost property to an XML file?

Giving the output for part number and zip code: It is possible to create a Boost property from a std::string, and then write the Boost property to an XML file: Upon navigating to the same project folder after running this, observe that the XML file has been created:

What is property tree in C++?

What is Property Tree? The Property Tree library provides a data structure that stores an arbitrarily deeply nested tree of values, indexed at each level by some key. Each node of the tree stores its own value, plus an ordered list of its subnodes and their keys.

What is a property tree in Python?

The Property Tree library provides a data structure that stores an arbitrarily deeply nested tree of values, indexed at each level by some key. Each node of the tree stores its own value, plus an ordered list of its subnodes and their keys.


1 Answers

Just write to a std::stringstream:

std::ostringstream oss;
boost::property_tree::ini_parser::write_ini(oss, my_ptree);

std::string inifile_text = oss.str();

Replace with wstring/wostringstream as appropriate

like image 161
sehe Avatar answered Sep 21 '22 08:09

sehe