You should be checking the calls to Open()
for failure. You forgot to close the file after you finished writing to it. Add fileS.Close();
after you close the archive object.
if(!fileS.Open(L"C:\\source\\CMyObject.dat", CFile::modeWrite | CFile::modeCreate))
{
std::cout << "Unable to open output file" << std::endl;
return 1;
}
CArchive arStore(&fileS, CArchive::store);
cm.Print();
cm.Serialize(arStore);
arStore.Close();
fileS.Close(); // <--- close the file
if(!fileL.Open(L"C:\\source\\CMyObject.dat", CFile::modeRead))
{
std::cout << "Unable to open input file" << std::endl;
return 1;
}
CArchive arLoad(&fileL, CArchive::load);
cm.Serialize(arLoad);
cm.Print();
arLoad.Close();
fileL.Close(); // <--- close the file