Assume I have a class
class A
{
char *attr1,*attr2;
public:
. . .
};
How to save the object of this class to file in a binary format and read it back?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Read about serialization. For example the Boost serialization library. They have a nice definition:
That said, such a solution is the 5-kg hammer that solves most serialization problems. It may be the case that you need something far simpler. For example, if you object only consists of a few
char*attributes you can save it in a simpler way. A general solution, however, would allow you flexibility in case your object gets more complex in the future.