Configuring XML-formatting itself I leave up to you.
#include <boost/iostreams/device/file.hpp>
#include <boost/iostreams/filter/line.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
namespace io = boost::iostreams;
class prefix_front_pusher: public io::line_filter /* may use wline_filter */
{
public:
using io::line_filter::string_type;
explicit prefix_front_pusher(const string_type &prefix):
m_prefix(prefix) {}
private:
string_type do_filter(const string_type &line) override
{
return m_prefix + line;
}
const string_type m_prefix;
};
int main()
{
io::filtering_ostream out;
out.push(prefix_front_pusher("/* my prefix */"));
out.push(io::file_sink("my_file.txt"));
boost::property_tree::ptree ptree;
ptree.put("hello", "world");
boost::property_tree::write_xml(out, ptree);
}