序列化包含字符结构* [英] Serializing struct containing char*
本文介绍了序列化包含字符结构*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到一个错误与序列化一个char *字符串错误C2228:左'.serialize'必须有类/结构/联合
我可以用一个标准: :字符串,然后从它那里得到一个const char *。但我需要的char *字符串。
I'm getting an error with serializing a char* string error C2228: left of '.serialize' must have class/struct/union
I could use a std::string and then get a const char* from it. but I require the char* string.
推荐答案
该错误消息说,这一切,有升压序列化不支持序列化指针的基本类型。
The error message says it all, there's no support in boost serialization to serialize pointers to primitive types.
您可以做这样的事情在店里code:
You can do something like this in the store code:
int len = strlen(string) + 1;
ar & len;
ar & boost::serialization::make_binary_object(string, len);
和负载code:
int len;
ar & len;
string = new char[len]; //Don't forget to deallocate the old string
ar & boost::serialization::make_binary_object(string, len);
这篇关于序列化包含字符结构*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文