title: Reading/Writing a map with pointers to a file c++
body: <p>I'm trying to read and write a std::map object to/from a file. the map type is </p>
  
  <pre><code>map&lt;string, Node*&gt;
  </code></pre>
  
  <p>and i have successfully written it to a file but unsuccessfully read it back.
  i'm not sure if i'm storing it correctly i think it's because i have pointers in the map (Node*) but i'm not sure. how can i fully write the entire map with all the objects it contains and then read it back perfectly. my current read/write methods are</p>
  
  <p>Read</p>
  
  <pre><code>template&lt;typename T&gt;
  T ReadObject(string path) {
      T num;
      ifstream infile;
      infile.open(path, ios::in|ios::binary);
      infile.read(reinterpret_cast&lt;char *&gt;(&amp;num),sizeof(T));
          infile.close();
      return num;
  }
  </code></pre>
  
  <p>Write</p>
  
  <pre><code>template&lt;typename T&gt;
  void WriteObject(string path, T&amp; num) {
         ofstream outfile;
         outfile.open (path, ios::out|ios::binary);
         outfile.write(reinterpret_cast&lt;char *&gt;(&amp;num),sizeof(T));
         outfile.close();
  }
  </code></pre>
  
  <p>btw these work when reading and writing integers</p>