-4

i have created a class as shown below

    class Registry
     {
        char m_name[20];
        char m_type[20];
        unsigned int m_value;
      public:
             Registry(char *name,char *type,int value=0)
             {
                     m_name=name;
                     m_type=type;
                     m_value=value;                       
             }

now i created a object as shown below

    Registry r1("alex","rez_sz",10);

now i want this object to be stored in a text file....plz tell me how to store the object in text file...?

shaik
  • 1
  • 3

3 Answers3

0

There's no builtin solution to write an object into a file. You have to serialize it.

Read this answer if you want more informations.

Community
  • 1
  • 1
nouney
  • 4,363
  • 19
  • 31
0

What you're looking to do is called serialization. One option is to write your own method that simply writes every value in the object to disk in a format of your own choosing, or you can use an external libray. You can find more information in this answer.

Community
  • 1
  • 1
IanPudney
  • 5,941
  • 1
  • 24
  • 39
0

What are you asking about is object serialization: http://en.wikipedia.org/wiki/Serialization

I recommend reading this question Is it possible to serialize and deserialize a class in C++?

and this page http://www.parashift.com/c++-faq-lite/serialization.html

Community
  • 1
  • 1
Avner Solomon
  • 1,486
  • 11
  • 17