Код: Выделить всё
// Add as another type for Cereal or inside string.hpp in Cereal includes
template inline
void CEREAL_SAVE_FUNCTION_NAME(Archive & ar, CString str)
{
// Save number of chars + the data
size_type size = (str.GetLength() + 1) * sizeof(TCHAR);
ar(size);
ar(binary_data(str.GetBuffer(), static_cast(size)));
str.ReleaseBuffer();
}
template inline
void CEREAL_LOAD_FUNCTION_NAME(Archive & ar, CString & str)
{
size_type size;
ar(size);
ar(binary_data(str.GetBuffer(static_cast(size)), static_cast(size)));
str.ReleaseBuffer();
}
Код: Выделить всё
class Stuff
{
public:
Stuff() {}
std::vector vec;
private:
friend class cereal::access;
template
void serialize(Archive & ar)
{
ar(vec);
}
};
int main()
{
Stuff myStuff, otherStuff;
myStuff.vec.push_back(L"Testing different length CStrings");
myStuff.vec.push_back(L"Separator");
myStuff.vec.push_back(L"Is it working yet??");
myStuff.vec.push_back(L"1234567890");
myStuff.vec.push_back(L"TestingTestingTestingtestingTesting");
{
std::ofstream file("out.txt", std::ios::binary);
cereal::BinaryOutputArchive output(file);
output(myStuff);
}
{
std::ifstream file("out.txt", std::ios::binary);
cereal::BinaryInputArchive input(file);
input(otherStuff);
}
int nSize = otherStuff.vec.size();
for (int x = 0; x < nSize; x++)
{
std::wcout
Подробнее здесь: [url]https://stackoverflow.com/questions/50652557/cereal-serialize-cstring-vector[/url]
Мобильная версия