1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <boost/property_tree/info_parser.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <string>
#include <iostream>
#include <functional>
struct _Config
{
std::string info[2];
boost::property_tree::ptree pt;
_Config()
{
info[0] = "If updating this file make sure to update all settings accordingly.";
info[1] = "This program has been created by Name 'Nickname' Lastname";
}
void Save()
{
boost::property_tree::info_parser::write_info("./config.cfg.ex", pt);
}
void Load()
{
boost::property_tree::info_parser::read_info("./config.cfg", pt);
{
//check if variable already exists in config file, if yes load it to
{
//try to load entry
boost::optional<std::string> v = pt.get_optional<std::string>("Info.a");
if (v.is_initialized())
//overwrite default value
info[0] = v.get();
}
//if entry does not exist it will be created now, else the loaded value will be saved
pt.put<std::string>("Info.a", info[0]);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
cat>config.cfg<<HERE; clang++ -std=c++11 -Os -Wall -pedantic -pthread main.cpp && ./a.out && cat ./config.cfg.ex
"Info"
{
    a "If updating this file make sure to update all settings accordingly."
    b "This program has been created by Name 'Nickname' Lastname"
}
HERE
Info
{
    a "If updating this file make sure to update all settings accordingly."
    b "This program has been created by Name 'Nickname' Lastname"
}