title: What is wrong with this code of file handling in c++?
body: <p>I am new to c++ and specifically file handling. 
  I made this code. </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  using namespace std;
  class student
  {
      public:
      char s;
      int age;
  };
  int main (void)
  {
      student a;
      a.s = 'a';
      a.age = 1;
      ofstream myfile;
      myfile.open("a1.txt",ios::app);
      myfile.write(reinterpret_cast&lt;char*&gt;(&amp;a),sizeof(student));
      return 0;
  }
  </code></pre>
  
  <p>When I opened the file <code>a1.txt</code>, it had the character a correctly in there, but for the integer it had some weird encoding and a message that if you continue to edit this file, it will be corrupted. Can't I write an object to a file containing an integer and a character or a string as well?</p>