title: How Read Write Functions work in File Handling OOP C++
body: <p>I'm working on File Handling with OOP and have come to know about little built-in functions <code>write()</code> &amp; <code>read()</code>But I don't know why it required casting. I also tried casting into <code>int*</code> instead of <code>char*</code> then casting not works. I tried googling but unable to find good tutorials or article.</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;fstream&gt;
  using namespace std;
  class Person{
      private:
          int age;
          char name[15];
          public:
              void getData()
              {
                  cout&lt;&lt;"Enter the name of person:";
                  cin&gt;&gt;name;
                  cout&lt;&lt;"Enter the age of person:";
                  cin&gt;&gt;age;
              }
                  void showData()
              {
                  cout&lt;&lt;"\nName  is:"&lt;&lt;name;
                  cout&lt;&lt;"\nAge is:"&lt;&lt;age;
              }
  };
  int main()
  {
      Person p;
      p.getData();
      ofstream outfile("Person.txt");
      outfile.write(reinterpret_cast&lt;char*&gt;(&amp;p), sizeof(p)); // how this works?
      ifstream infile("Person.txt");
      infile.read(reinterpret_cast&lt;char*&gt;(&amp;p), sizeof(p)); // how this works?
      p.showData();
      return 0;
   }
  </code></pre>
  
  <p>Can you tell me why Casting required? and why sizeof operator?</p>