Is it possible to serialize and deserialize a class in C++?
I've been using Java for 3 years now, and serialization / deserialization is fairly trivial in that language. Does C++ have similar features? Are there native libraries that handle serialization?
An example would be helpful.
The only native way to do it is to use streams. That's essentially all the
Boost::serialization library does, it extends the stream method by setting up a framework to write objects to a text-like format and read them from the same format.
For built-in types, or your own types with
operator>> properly defined, that's fairly simple; see the C++ FAQ for more information.
I realize this is an old post but it's one of the first that comes up when searching for
I encourage anyone who has access to C++11 to take a look at cereal, a C++11 header only library for serialization that supports binary, JSON, and XML out of the box. cereal was designed to be easy to extend and use and has a similar syntax to Boost.