I have an application where I need some data to persist, so I thought about object serialization. I found a nice example here. Following it, this is what I came up with:
std::stack <std::string> cards;
cards.push("King of Hearts");
std::ofstream ofs("<location>", std::ios::binary);
ofs.write((char *)&cards, sizeof(cards));
ofs.close();
Then I am trying to read the data:
std::stack<std::string> inp;
std::ifstream ifs("<same_location>", std::ios::binary);
ifs.read((char *)&inp, sizeof(inp));
However the app is crashing at the last line (for some reason, due to my Qt settings, I am unable to debug currently). What can be the possible error, and how do I fix this?