i've got another problem hope that's the last one. I've been searching and trying diffrent think but i don't know what to do.
I've got some array of classes stored in file
Code:
void Newmap(char file[]) //Create new map file
{
ofstream fout(file,ios::binary | ios::trunc);
class Mapsqr Map[Map_Size][Map_Size];
int coords[2];
for (int i=0;i<Map_Size;i++)
{
for (int j=0;j<Map_Size;j++)
{
Map[i][j].SetParameters(i,j,Plains);
}
}
fout.write((char*) &Map,sizeof Map);
fout.close();
}
i can read it and everything is fine up to a point where i want to replace one Mapsqr class element in file.But i don't wont to read whole file and then rewrite it because it can be quit large. So i set a put pointer to corect place and wont to overwrite one element and end up with file with overwriten element end cutted off after it.
Code:
void EditOneTerrain (char file[],int coords[],TerrainType towhat)//edit terrain type
{
class Mapsqr tmp;
ofstream fout(file,ios::binary);
tmp.SetParameters(coords[X],coords[Y],towhat);
for (int i=0;i<coords[X];i++)
{
fout.seekp(Map_Size*sizeof(tmp), ios::cur);
}
for (int i=0;i<coords[Y];i++)
{
fout.seekp(sizeof(tmp), ios::cur);
}
fout.write((char*) &tmp,sizeof tmp);
system("pause");
fout.close();
}
When i read the file there are all the elements up to the changed one, but after it file ends. What's wrong? Does write automaticaly truncate file after it?