I always saved data by writing ASCII to files, i.e.
param1 = value1 param2 = string string string
and downloaded it with an annoying amount of parsing overhead. I was just trying to run my programming program by writing an entire object in a binary file, la
class Record { int par1; string par2; vector<string> par3; void saveRecord(string fName); void loadRecord(string fName); } Record::saveRecord() { ... fstream outFile(fName.c_str(), fstream::out | fstream::binary); outFile.write( (char*)this, sizeof(Record) ); outFile.close(); }
etc. But I found out that this does not work, because complex data types (for example, string, vector) contain pointers whose values cannot be stored in this way.
So these are the parameters
A) Write complex serialization algorithms to convert all complex data types to primitives, and then save them in binary; or
B) Just write everything in an ASCII file according to my original strategy.
The first method seems too complicated, and the second - elegant.
Are there any other options? Is there a standard procedure?
Note. I saw the boost :: serialization library, which also looks very inelegant and strangely cumbersome, that is, I would just write my own serialization methods if it were the right methodology.