title: read dynamic memory allocated string (char*) from binary file C++
body: <p>I am trying to make students database by this types: (class Student)</p>
  
  <pre><code>class Student {           
      unsigned Id;//ID number
      char* name;// dynamic memory allocated name (size: 10)
      char* family;// dynamic memory allocated last name (size: 10)
      int gen;//gender
      unsigned MiddleTestGrade;// grade of the student in the middle test
      unsigned FinalTestGrade;// grade of the student in the final test
      double TotalGrade;// total grade of the student calculates automaticly (dont need to insert this as input)
  };
  </code></pre>
  
  <p>I write all this information to a binary file using this command:(StudentData type is the Student class mentioned above)</p>
  
  <pre><code>file.write(reinterpret_cast&lt;const char*&gt;(&amp;StudentData),sizeof(Student));
  </code></pre>
  
  <p>When I use the read command to get all the data from the file:</p>
  
  <pre><code>file.read(reinterpret_cast&lt;char*&gt;(&amp;StudentData),sizeof (Student));
  </code></pre>
  
  <p>the result is that everything read good except for the dynamic allocated names.   These contain only the last name that i write to the file.</p>
  
  <p>For example after I insert 2 students into the file:</p>
  
  <blockquote>
    <p>12 Jhon Sna 1 95 100</p>
  </blockquote>
  
  <p>and</p>
  
  <blockquote>
    <p>77 David Gen 1 80 85</p>
  </blockquote>
  
  <p>the result of the reading and printing will be:</p>
  
  <blockquote>
    <p>12 David Gen 1 95 100</p>
  </blockquote>
  
  <p>and</p>
  
  <blockquote>
    <p>77 David Gen 1 80 85</p>
  </blockquote>
  
  <p>When i use string (not dynamic allocated) everything works like it should :\</p>
  
  <p>What am I doing wrong?</p>