I'm trying to use file streams to save my maps from my editor, but ios::binary is giving me problems. It doesn't seem to output everything in binary. It also causes the end of the file to be a repeat of the beginning or something. I don't know how to explain it, it's so weird
. Can anyone help me out?
saving:
ofstream file;
file.open(filepath,ios::out | ios::binary);
unsigned short mapsize = (unsigned short)landscape.GetSize();
unsigned char** tilemap = landscape.GetTilemap();
float** heightmap = landscape.GetHeightmap();
file << mapsize;
for(int i=0;i<mapsize;i++) {
for(int j=0;j<mapsize;j++) {
file << tilemap[i][j];
}
}
for(int i=0;i<mapsize+1;i++) {
for(int j=0;j<mapsize+1;j++) {
file << heightmap[i][j];
}
}
file.close();
loading:
ifstream file;
file.open(filepath,ios::in | ios::binary);
unsigned short size;
file >> size;
unsigned char** tilemap;
float** heightmap;
tilemap = new unsigned char*[size];
heightmap = new float*[size+1];
for(int i=0;i<size;i++) {
tilemap[i] = new unsigned char[size];
for(int j=0;j<size;j++) {
file >> tilemap[i][j];
}
}
for(int i=0;i<size+1;i++) {
heightmap[i] = new float[size+1];
for(int j=0;j<size+1;j++) {
file >> heightmap[i][j];
}
}
file.close();
[edited by - Raloth on October 5, 2003 10:17:08 PM]