Reading from file.But only part of it.
Ok i've got some problem.I have function that saves array of class objects to a file using write function from fstream.h
Code:
#include<iostream.h>
#include<fstream.h>
#include"Mapsqr.h"
void Newmap(char file[])
{
ofstream fout(file,ios::binary);
class Mapsqr Map[100][100];
fout.write((char*) &Map,sizeof Map);
fout.close();
}
Now i want to read from that file but not the whole 100x100 array but only an smaller one let say 20 on 20 such that it would be elements from squer map[51][23] to map [71][53].
if i make it like this
Code:
void Readmap(char file[])
{
class Mapsqr tmpmap[20][20];
ifstream fin(file,ios::binary);
fin.read((char*) &tmpmap,sizeof tmpmap);
fin.close();
}
then tmpmap[0][0] will be element that was in map[0][0] but at tmpmap[1][0] i will have element that was map[0][20] not map[1][0].
so how to make it such way that tmpmap[1][0] will have same data as map[1][0]? How to tell program from where to read. Do i have to do such thing to get map[0][67] element or is there some way to tell program where to begin to read?
Code:
void Readelementmap(char file[])
{
class Mapsqr tmp;
ifstream fin(file,ios::binary);
for (int i=0;i<67;i++)
{
fin.read((char*) &tmp,sizeof tmp);
}
fin.close();
}