[Solved] How to implement file reading and creating into a structure [closed]


assuming your config is splitted in sections like:

[myImportantSection] 
someBigText = "foo tha can be more +1000 simbols" 
isOkay = true 
myAge = 24

and assuming you are using boost:

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>



boost::property_tree::ptree myPtree;
boost::property_tree::ini_parser::read_ini("config.txt", myPtree);
auto text{myPtree.get<std::string>("myImportantSection.someBigText")};
auto isOk{myPtree.get<bool>("myImportantSection.isOkay")};
auto age{myPtree.get<int>("myImportantSection.myAge")};

struct Config
{
    std::string text{};
    bool ok{false};
    int age{0};
};

Config myConfig;

myConfig.text = text;
myConfig.ok = isOk;
myConfig.age = age;

solved How to implement file reading and creating into a structure [closed]