Saving a Class Object Into a File

Here's the class:
class Frame
   string Name;
   char FramePixels[20][20];
   int SequenceNum;

I want to be able to save this to a file, and be able to load it. Is there a simple way of doing this?
closed account (DSLq5Di1)
The method in that tutorial is an old C solution, simple to implement, but doesn't play nice with C++, and is machine/compiler dependent.

I'd overload the stream operators and output the data members to a plain text file. If you want something fancier, consider using the boost serialization library.
I agree with sloppy9

I quite often use XML as my serialization format, but then I have boiler plate code available to do most of the work. For a one off, custom code would prob be ok. You only real bit of work would be code to read and write the array safely.

If you want to learn a reusable approach though, it could be worth looking at one of the established libraries. In addition to Boost.Serialization, you could consider a JSON or YAML library. I've only played with these (we use XML at work...), but they look more friendly than XML.

And then there's XML

Last edited on
Topic archived. No new replies allowed.