I want to simply read this into a char (just to see how it works) so from that point i can do the specifics like reading a number into an int. Just wondering how i would start this off. I tried:
Yea i had char chr[800]; before and took it out to see if it would work. Im getting a bunch of of weird characters stored in chr[800] when i display it.
Thats what im not sure about because my professor made the .dat file. He told the class to read the list of students form the binary file (its a file with student names and courses they are taking), sort it and create an ASCII file with it.
Without the file format, you can't really extract any meaningful data from it. He MUST have told you something like, "First four bytes are an int length, the next length bytes are a string" etc.
That's actually exactly what you need to read the file since now you know the structure it was written in. It's been a while since I have dealt with bin files so I don't remember the exact syntax, but the data in the file will follow the structure of the class exactly.
So a read of ((char *)x, sizeof(double * MAX_COURSES)) will give you the Marks field that was written to the file.
Can't remember exactly but you might even be able to read the whole class into a StudentRecordData object with a single instruction.
That's actually exactly what you need to read the file since now you know the structure it was written in.
No you don't. There is quite a number of ways to serialize this. Though unless your professor is an... a not very nice person I mean to say, he will probably have just casted everything to char* and written it to the file in the order he declared the members. Though that means you're f*ed if your system has another endianess or a different size for any of the types than the one your professor is using.
Can't remember exactly but you might even be able to read the whole class into a StudentRecordData object with a single instruction.
Not really, unless you already have a deserialization function available.
is.read(reinterpret_cast<char *>(Marks), sizeof(double)*18); and is.read(reinterpret_cast<char *>(Age), sizeof(int)); are things you should never do.
If Age is an integer, reinterpret_cast<char *>(Age) will make it try to read to the location with the same address as the value of Age. Eg: if Age=0, it will try to read at location 0