title: C++: how to serialize/deserialize objects without the use of libraries?
body: <p>I am trying to understand how serialization/deserialization works in C++ without the use of libraries. I started with simple objects but when deserializing a vector, I found out, that I can't get the vector without having written its size first. Moreover, I don't know which file format I should choose, because, if digits exist before vector's size I can't read it right. Furthermore, I want to do that with classes and map containers. My task is to serialize/deserialize an object like this:</p>
  
  <pre><code>PersonInfo
  {
      unsigned int    age_;
      string name_;
      enum { undef, man, woman } sex_;
  }
  
  Person : PersonInfo 
  {
      vector&lt;Person&gt;      children_;
      map&lt;string, PersonInfo&gt;     addrBook_;
  }
  </code></pre>
  
  <p>Currently I know how to serialize simple objects like this:</p>
  
  <pre><code>vector&lt;PersonInfo&gt; vecPersonInfo;
  vecPersonInfo.push_back(*personInfo);
  vecPersonInfo.push_back(*oneMorePersonInfo);
  
  ofstream file("file", ios::out | ios::binary);
  if (!file) {
      cout&lt;&lt;"can not open file";
  } else {
      vector&lt;PersonInfo&gt;::const_iterator iterator = vecPersonInfo.begin();
      for (; iterator != vecPersonInfo.end(); iterator++) {
          file&lt;&lt;*iterator;
      }
  </code></pre>
  
  <p>Could you please suggest, how can I do this for this complex object or a good tutorial that explains it clearly?</p>