boost :: property_tree :: info_parser unterbricht Leerzeichen im Wert
Ich stehe vor einem Problem, bei dem ich eine Konfigurationsdatei habe und diese mit boost :: property_tree: info_parser analysiere.
Ich benutze diesen Code, um die Arbeit zu erledigen:
struct _Config
{
std::string info[2];
boost::property_tree::ptree pt;
_Config()
{
//check if config file exists, if not create it, etc, do other stuff not related to the issue
//this code reproduces the issue
//DEFAULT VALUE, can be changed by configuration later
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", 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]);
}
//again for next variable
{
{
boost::optional<std::string> v = pt.get_optional<std::string>("Info.b");
if (v.is_initialized())
info[1] = v.get();
}
pt.put<std::string>("Info.b", info[1]);
}
Save();
}
~_Config()
{
Save();
pt.clear();
}
} Config;
Nun sieht mein Bereich das erste Mal so aus:
Info
{
a "If updating this file make sure to update all settings accordingly."
b "This program has been created by Name 'Nickname' Lastname"
}
beim erneuten starten wird meine konfiguration so beim speichern:
Info
{
a If updating this file make sure to update all settings accordingly.
b This program has been created by Name 'Nickname' Lastname
}
aber nach einem erneuten Neustart des Codes wird der Info-Bereich zu einem Chaos und mein Programm bricht ab:
Info
{
a If
updating this
file make
sure to
update all
accordingly. ""
b This
program has
been created
by Name
'Nickname' Lastname
}
Wie stelle ich sicher, dass Leerzeichen als Zeichen akzeptiert werden und die Anführungszeichen nicht entfernt werden? Ich habe auch bemerkt, dass alle Kommentare, die ich in der Konfigurationsdatei mache, nicht gespeichert werden. Gibt es eine Option, um sie zu speichern?
Ich verwende Boost 1.55 mit Visual Studio 2013 unter Windows 8 x 64 in einer 32-Bit-Anwendung.