dumping of object directly into a file, will save member variables into stream.
So the roll number, marks and name will be dumped. The memory layout of the object will get reflected in file also. So you can check memory view of object, in the same way it will be dumped.
But writing object like this is not a good practice as reading of object requires lots of maintenance. Since a little change in your student class will impact reader code also.
Your last question is not clear to me, can you elaborate more on that part.
tajendra
Junior Poster in Training
53 posts since Mar 2010
Reputation Points: 34
Solved Threads: 7
So You are telling me to create a separate class for student file ?
no, he's telling you to not blindly serialise objects at all.
Instead define a well documented file format containing the fields you want in the order you want, and create readers and writers for that format producing and consuming instances of the class (methods that may or may not be members of the class).
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
He said define the data layout. Add methods to load and retrieve the data elements. Add methods to read and write the data elements.
Try this:
Make sure NAME is your first data element.
Write the class
Immediately write the string ""
Examine at the file in binary.
Make your changes to the class.
Do the above again.
Compare the first file to the second.
If the files are identical, the changes do not affect your file.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944