Ok so, having looked at the numerous other posts on problems with binary files (reading/writing) I cannot see what I am doing wrong.
Code:void CFile::SaveFile() { std::ofstream fout; fout.open(filename.c_str(), std::ios::out | std::ios::binary); if( fout.is_open() ) { for(int loop = 0; loop < MAX_DATA_SIZE; loop++) fout.write((char *)&DataList[loop], sizeof(CHighScore)); fout.close(); } }
This part seemingly works just fine, MAX_DATA_SIZE is 10, CHighScore is 8 bytes, and I end up with a saved file of 80 bytes.
But when I go to read it in, it opens the file, then shuts right down.
I've also tried taking out the loop and just reading a single instance from the file, so I know I am just not understanding/missing something.
Code:void CFile::LoadFile() { std::ifstream fin; fin.open(filename.c_str(), std::ios::in | std::ios::binary); if( fin.is_open() ) { for(int loop = 0; loop < MAX_DATA_SIZE; loop++) { CHighScore temp; fin.read((char *)&temp, sizeof(CHighScore)); DataList.push_back(temp); } fin.close(); } else DefaultBuild(); }



1Likes
LinkBack URL
About LinkBacks



