title: fstream::write and fstream::read changing both reading and writing pointers
body: <p>I am learning about how to write records on file and read it .<br>
  I created a class called <code>student</code> , the class has function like <code>enterStudent</code> , <code>showStudent</code> , <code>printInsideFile</code> (student info) ,...... .<br>
  when I try to write student info into the file , it works .<br>
  when I try to read all student info from the file , it works <br>
  when I try to do both , something unexpected happens (nothing show up)</p>
  <p>i thought that the problem with <code>file.flush()</code> , so when i deleted it the output was unreadable text<br>
  i could close the file and open it again but i think that is silly<br>
  <strong>the code is:</strong></p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  
  
  using namespace std;
  
  class student {
  private:
      char id[5], name[20], age[5], address[50], gender[5];
  public:
      void enterStudent() {
          cout &lt;&lt; &quot;Enter student id : &quot;; cin &gt;&gt; id;
          cout &lt;&lt; &quot;\nEnter student name : &quot;; cin &gt;&gt; name;
          cout &lt;&lt; &quot;\nEnter student age : &quot;; cin &gt;&gt; age;
          cout &lt;&lt; &quot;\nEnter student address : &quot;; cin &gt;&gt; address;
          cout &lt;&lt; &quot;\nEnter student gender : &quot;; cin &gt;&gt; gender;
  
      }
      void showStudent() {
          cout &lt;&lt; &quot;#########student data##########\n&quot;;
          cout &lt;&lt; &quot;student id : &quot;&lt;&lt; id;
          cout &lt;&lt; &quot;\nstudent name : &quot; &lt;&lt; name;
          cout &lt;&lt; &quot;\nstudent age : &quot; &lt;&lt; age;
          cout &lt;&lt; &quot;\nstudent address : &quot; &lt;&lt; address;
          cout &lt;&lt; &quot;\nstudent gender : &quot; &lt;&lt; gender&lt;&lt;endl;
      }
      void printInsideFile(fstream &amp;file) {
          file.write(id,sizeof(id));
          file.write(name, sizeof(name));
          file.write(age, sizeof(age));
          file.write(address, sizeof(address));
          file.write(gender, sizeof(gender));
          file.flush();
      }
      bool readFromFile(fstream &amp;file) {
          if (file.eof())
              return 0;
          file.read(id, sizeof(id));
          file.read(name, sizeof(name));
          file.read(age, sizeof(age));
          file.read(address, sizeof(address));
          file.read(gender, sizeof(gender));
          if (file.eof())
              return 0;
          return 1;
      }
      void showAllFromFile(fstream &amp;file) {
          while (this-&gt;readFromFile(file)) 
              this-&gt;showStudent();
      }
  };
  
  int main() {
      student s;
      fstream file;
  
      file.open(&quot;a.txt&quot;, ios::in | ios::out | ios::app);
      if (!file)
          goto k270;
      
      s.enterStudent();
      s.printInsideFile(file);
  
      //when i read one student , it works okay
  
      //s.readFromFile(file);
      //s.showStudent();
  
      //when i try to read multiple students , it doesn't work at all
      s.showAllFromFile(file);
  
  
  
  
      file.close();
  
  
  k270:
      system(&quot;pause&quot;);
      return 0;
  }
  </code></pre>