I’m trying to read encrypted struct data from file using fread(). once i get the decrypted struct bytes, I’d like to it put them back into this struct.
struct data
{
std::string s1;
std::string s2;
std::string s3;
LONG l;
};
how would you convert a struct into bytes which can be reconstructed from bytes?
The problem is that
std::stringdoes not contain the bytes in question, it contains a pointer to the bytes you actually want to store. You should probably save each string as a null terminated string, and then save a raw long after that, in the file.If you’re looking for a “point and click” serialization solution like that provided by .NET, you will not find what you’re looking for in C++. Boost’s serialization library may be helpful because it will serialize some standard library objects for you, but you’ll need your own implementation for a user defined class like that.