XML ファイルの単純な入出力を行う必要があります。私はboost::ptreeを使用しています。
struct structure
{
std::string str;
int ival;
std::list<bool> bval;
void save(const std::string& filename) {
ptree pt;
pt.put("main.str", str);
pt.put("main.ival", ival);
for (const auto& x : bval)
pt.put("main.bval.b", x);
write_xml(filename, pt);
}
void load(const std::string& filename) {
ptree pt;
read_xml(filename, pt);
str = pt.get("main.str", str);
ival = pt.get("main.ival", ival);
for(auto& v : pt.get_child("main.bval"))
bval.insert(v.second.data());
}
};
int main()
{
structure b, s;
s.str = "abc";
s.ival = 14;
s.bval = { 1, 0, 0, 1, 0, 1, 0, 0, 0, 1 };
try
{
s.save("zxx.xml");
b.load("zxx.xml");
}
catch (std::exception& exc)
{
std::cout << exc.what() << std::endl;
}
return 0;
}
「bval」の 1 つの要素のみがファイルに書き込まれるため、入力が正しく機能しません。また、このコンテナ(bval)の出力の仕方がわかりません。助けてください!