I have a class named object that have some instance vars. I want to save it to file. How can I cast it to type(e.g. int) that can be written to file?
Asked
Active
Viewed 714 times
0
-
1You might take a look at http://stackoverflow.com/questions/523872/how-do-you-serialize-an-object-in-c – John Flatness May 08 '11 at 06:52
2 Answers
4
If I understand correcty you want to save an object to hard drive? That is called serialization. You might want to check the boost library for that.

Andro
- 2,232
- 1
- 27
- 40
-
You correctly understood me. Could you tell me some libraries for this? And there isn't way to do it with standard c++ libs really(I want my program will be independent third-party libs)? – HiTECNOLOGYs May 08 '11 at 07:44
-
Well I dont really know this thing in details, you should check the doczumentation. But a fair wairning: C++ serialization with nothing but standard library is not going to be easy especially if you are doing this for the first time. It not like Java where you just implement the serializable interface. – Andro May 08 '11 at 09:33
1
If it has several data members - you cannot do this (without using some external (3rd party) lib - that's an addition). Instead, write your own function for storing your object into a file, and one for reading from it.

Kiril Kirov
- 37,467
- 22
- 115
- 187