开发者

File operation in C++

I have written an object to file but when I read the object from the file, it is not getting the correct value. If 1 object is considered as 1 record and if only 1 record is there in the file, it's getting the value. If I write more records (many objects of the same type) then it's not getting the v开发者_运维知识库alue.


There could be a couple of problems. Of the top of my head it might be an issue with how you are interfacing with the file, as the comments above indicate. Or it might be a serialization issue.

I recently learned that one cannot simply write a class to a file because its not guaranteed to be contiguous memory (other reasons too, but the moral I took was don't do it).

Instead one needs to serialize the object/class before writing it to the file.

A couple of web resources that I found useful for this are:

http://functionx.com/cpp/articles/serialization.htm (I liked this one a lot).

http://functionx.com/cpp/articles/serialization.htm

Is it possible to serialize and deserialize a class in C++?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜