I need to ser开发者_高级运维ialize std::wstring by my own method. How to force boost to use my methods of serialization instead of default methods? Thanks.
Untested, but you'd want to specialize boost::serialization::archive for your data type:
namespace boost { namespace serialization { template<class Archive> void serialize(Archive & ar, std::wstring& s, const unsigned int version) { for (std::wstring::iterator it = s.begin(); it != s.end(); ++it) ar >> *it } } // namespace serialization } // namespace boost
This code should basically work as-is, you'd just want to change the contents of the serialize function (but not the signature.)
Why you'd want to serialize a wstring in any other way than just printing it (ie. just using normal iostreams), I have no idea.
精彩评论