开发者

boost.serialization and replace existing method of serializing std::wstring

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜