read Binary Data file onto class
Hey guys,
I 'm having problem reading data from a text file.
Sample.dat contains
M
Bob
Dude
56
F
Carmen
Sandiago
33
VP
my code is suppose to read the .DAT file using ios::binary
and feed the information into a class.
example class...
class personInfo
{
char firstname[20];
char lastname[20];
int age;
char gender;
}
class femleInfo : public personInfo
{
char title[5];
}
acutally I have a polymorphic function that reads male info into a maleInfo Class and femaleInfo into a femaleInfo class.
The problem is,how do I read both male and female info seperately and load the appropriate class? (they both have differnt number of data members)....
I tried using seekg function and to move the pointer but I didnt really understand it,
another problem Im having is, how to read the the data from file into my class ???
I tried myDataFile.read(reinterpret_cast (&fObject),fObjSize);
and I thought this would copy each data item from the text file into the class varibales???
that doenst seem to be happening, am I missing something?
Can someone pls help.