C++ 将对象放入boost::property_树的正确方法是什么?
考虑以下示例:C++ 将对象放入boost::property_树的正确方法是什么?,c++,boost,boost-propertytree,C++,Boost,Boost Propertytree,考虑以下示例: #include <boost\property_tree\ptree.hpp> #include <boost/any.hpp> typedef boost::property_tree::ptree PT; struct Foo { int bar; int egg; Foo(): bar(), egg() {} }; int main() { Foo foo; foo.bar = 5; PT p
#include <boost\property_tree\ptree.hpp>
#include <boost/any.hpp>
typedef boost::property_tree::ptree PT;
struct Foo
{
int bar;
int egg;
Foo(): bar(), egg() {}
};
int main()
{
Foo foo;
foo.bar = 5;
PT pt;
pt.put<Foo>("foo", foo);
return 0;
}
#包括
#包括
typedef boost::property_tree::ptree PT;
结构Foo
{
int-bar;
内特蛋;
Foo():bar(),egg(){}
};
int main()
{
富富,;
foo.bar=5;
PT;
pt.put(“foo”,foo);
返回0;
}
我是boost新手,我愿意将一个Foo对象放入属性树中。上面的示例不会编译,但会出现错误:
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../../../../../include/boost/property\u tree/stream\u translator.hpp:33:13:错误:与“operator”不匹配只需创建一个重载的运算符。如果您有operator@NicolBolas当前位置是否有我遗漏的其他选项?我看不出有什么方法可以重载操作符
ostream& operator<<(ostream& out, Foo output_object)
{
out << egg << " " << bar;
return out;
}
Foo test;
cout << test; //will print out whatever the values of "egg" and "bar" are