title: c++ weird characters appear while writing to a file
body: <p>When i run this code, and open the .dat file in notepad/wordpad it shows some weird characters</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;fstream&gt;
  using namespace std;
  
  class Student
  {
      int rollno;
      char name[20];
      char div[20];
  public:
      void accept()
      {
          cout&lt;&lt;"enter rollno"&lt;&lt;endl;
          cin&gt;&gt;rollno;
          cout&lt;&lt;"Enter name"&lt;&lt;endl;
          cin&gt;&gt;name;
          cout&lt;&lt;"Enter div"&lt;&lt;endl;
          cin&gt;&gt;div;
      }
      void write_rec()
      {
          ofstream f;
          f.open("Student.dat",ios::binary|ios::app);
          Student s;
          s.accept();
          f.write((char*)&amp;s,sizeof(s));
          f.close();
      }
      void display()
      {
          ifstream f;
          Student s;
          f.open("Student.dat",ios::binary|ios::in);
          while(f.read((char*)&amp;s,sizeof(s)))
              s.show();
          f.close();
      }
      void show()
      {
          cout&lt;&lt;rollno&lt;&lt;endl;
          cout&lt;&lt;name&lt;&lt;endl;
          cout&lt;&lt;div&lt;&lt;endl;
      }
  };
  int main()
  {
      Student s;
      s.write_rec();
      s.display();
  
  }
  </code></pre>
  
  <p>The code is getting compiled and run perfectly but when i open the "Student.dat" file it shows some weird characters</p>