I need to serialize std::wstring by my own method.
How to force boost to use my methods of serialization instead of default methods?
Thanks.
I need to serialize std::wstring by my own method. How to force boost to
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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 boostThis 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.