So here is the situation:
I want to be able to store a bunch of objects (which will probably be be stored in a linked list but that is not finalised) In a file.
What would be the most efficient way of doing so?
Storing all the objects attributes and then reading them from the file when creating the objects on each run?
Or is there a way to store a whole object/datastructure as a binary file so It can be easily chucked into the program.
class A
{
private:
int prop1;
int prop2;
};
typedef std::list < A > Container;
class WriteToFile
{
public:
WriteToFile(ofstream& to) : m_file(to){}
voidoperator()(const A& element) const
{
//here your code, which implements saving
// but you need to use m_file as output stream
}
private:
ofstream& m_file;
};
Container myData;
.....
std::ofsrem to("serialization.dat");
std::for_each(myData.begin(), myData.end(), WriteToFile(to));
And of course you need another solution, if your class has pointers