title: how to correctly write vector to binary file in c++?
body: <p>first sorry for my bad english. i am just joined this forum and search for
  how to correctly write vector to binary file. i just got from this forum an answer like this(i have modified it a little):</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string.h&gt;
  #include &lt;vector&gt;
  #include &lt;fstream&gt;
  
  using namespace std;
  
  class Student
  {
  public:
  char m_name[30];
  int m_score;
  
  public:
  Student()
  {
  
  }
  Student(const char name[], const int &amp;score)
  :m_score(score)
  {
      strcpy(m_name, name);
  }
  void print() const
  {
      cout.setf(ios::left);
      cout.width(20);
      cout &lt;&lt; m_name &lt;&lt; &quot; &quot; &lt;&lt; m_score &lt;&lt; endl;
  }
  };
  
  
  int main()
  {
      vector&lt;Student&gt; student;
      student.push_back(Student(&quot;Alex&quot;,19));
      student.push_back(Student(&quot;Maria&quot;,20));
      student.push_back(Student(&quot;muhamed&quot;,20));
      student.push_back(Student(&quot;Jeniffer&quot;,20));
      student.push_back(Student(&quot;Alex&quot;,20));
      student.push_back(Student(&quot;Maria&quot;,21));
  
      ofstream fout(&quot;data.dat&quot;, ios::out | ios::binary);
      fout.write((char*) &amp;student, sizeof(student));
      fout.close();
  
      vector&lt;Student&gt; student2;
  
      ifstream fin(&quot;data.dat&quot;, ios::in | ios::binary);
      fin.seekg(0, ifstream::end);
      int size = fin.tellg() / sizeof (student2);
      student2.resize(size);
      fin.seekg(0, ifstream::beg);
      fin.read((char*)&amp;student2, sizeof(student2));
      vector&lt;Student&gt;::const_iterator itr = student2.begin();
      while(itr != student2.end())
      {
              itr-&gt;print();
              ++itr;
      }
      fin.close();
      return 0;
  }
  </code></pre>
  <p>but when i run it. on my linux mint i got this result:</p>
  <blockquote>
  <pre><code>Alex                 19
  Maria                20
  muhamed              20
  Jeniffer             20
  Alex                 20
  Maria                21
  *** glibc detected *** ./from vector to binary: corrupted double-linked list: 0x0000000000633030 ***
  </code></pre>
  </blockquote>
  <p>i am new to c++.
  some one please help me, been stuck in this problem last 2 weeks.
  thanks in advance for the answer.</p>