Hi guys,
I'm trying to write to file a vector of classes and then reading it from file, but I don't get it working. The code compiles and the program creates the file, but with what seems garbage (I'm not writing in binary mode). This is the code:
foutBuddiesList.write(reinterpret_cast<char *>(&(buddiesList)), buddiesList.size() * sizeof(cBuddy));
cBuddy is the class and buddiesList is the vector containing the data. What am I doing wrong? Do I have to do a loop to append each vector member at a time?
Thanks for the help.
Figure this out? Does it matter that you have &(buddiesList) instead of &buddiesList?
If your buddiesList is a class then wouldn't that write the internal class structure to disk? Where is the member containing the vectors? I thought you would need to store the vector pointer in the class and write that pointer to disk.