我需要用我自己的方法序列化 std::wstring。 如何强制 boost 使用我的序列化方法而不是默认方法? 谢谢。
最佳答案
未经测试,但您希望针对您的数据类型专门化 boost::serialization::archive:
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
这段代码基本上应该按原样工作,您只想更改序列化函数的内容(而不是签名。)
为什么您想要以任何其他方式序列化 wstring 而不仅仅是打印它(即仅使用普通的 iostream),我不知道。
关于c++ - boost.serialization 并替换现有的序列化 std::wstring 的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3629332/