J
JoeC
I am writing a program that I am trying to learn and save binary
files. This is the page I found as a source:
http://www.angelfire.com/country/aldev0/cpphowto/cpp_BinaryFileIO.html
I have successfully created and used txt files.
I am trying to save then load in an array of pointers to objects:
class Map{
int xlen;
int ylen;
int mapTotal;
HWND hwnd;
space * playArea;
grTerrain grTerr;
....
Map::Map(HWND h, const int x, const int y){
xlen = x;
ylen = y;
hwnd = h;
playArea = new space[(xlen * ylen)];
create();
}
void Map::load(std::ifstream& f){
f.seekg (0);
f.read((char*)&mapTotal, sizeof(int));
f.read((char*)&playArea, sizeof(space) * mapTotal);
MessageBox(NULL, "Loading...", "Simulation", MB_OK);
}
void Map::save(std:fstream& f){
f.seekp (0);
f.write((char*)&mapTotal, sizeof(mapTotal));
f.write((char*)&playArea, sizeof(space));
MessageBox(NULL, "Saving...", "Simulation", MB_OK);
}
case ID_LOAD: {
std::ifstream f("data.bin", ios::in | ios::binary);
board->load(f);
f.close();
InvalidateRect(hwnd,NULL,FALSE);
break;
}
case ID_SAVE:{
std:fstream f("data.bin", ios:ut | ios::binary);
board->save(f);
f.close();
break;
}
I posted the parts of the program that apply to the saving and
loading. The program does save and creates a bin files 53kb so it
seems like the data is saving but unlike txt files, it is hard to
verify if the informations saved correctly.
files. This is the page I found as a source:
http://www.angelfire.com/country/aldev0/cpphowto/cpp_BinaryFileIO.html
I have successfully created and used txt files.
I am trying to save then load in an array of pointers to objects:
class Map{
int xlen;
int ylen;
int mapTotal;
HWND hwnd;
space * playArea;
grTerrain grTerr;
....
Map::Map(HWND h, const int x, const int y){
xlen = x;
ylen = y;
hwnd = h;
playArea = new space[(xlen * ylen)];
create();
}
void Map::load(std::ifstream& f){
f.seekg (0);
f.read((char*)&mapTotal, sizeof(int));
f.read((char*)&playArea, sizeof(space) * mapTotal);
MessageBox(NULL, "Loading...", "Simulation", MB_OK);
}
void Map::save(std:fstream& f){
f.seekp (0);
f.write((char*)&mapTotal, sizeof(mapTotal));
f.write((char*)&playArea, sizeof(space));
MessageBox(NULL, "Saving...", "Simulation", MB_OK);
}
case ID_LOAD: {
std::ifstream f("data.bin", ios::in | ios::binary);
board->load(f);
f.close();
InvalidateRect(hwnd,NULL,FALSE);
break;
}
case ID_SAVE:{
std:fstream f("data.bin", ios:ut | ios::binary);
board->save(f);
f.close();
break;
}
I posted the parts of the program that apply to the saving and
loading. The program does save and creates a bin files 53kb so it
seems like the data is saving but unlike txt files, it is hard to
verify if the informations saved correctly.