title: Updating student record in binary file, deletes previous data aswell
body: <p>I am trying to update student record by searching his roll no and then moving to that position using tellg() and seekp(). But whenever I try to overwrite, it deletes previous record.</p>
  
  <pre><code>int pos=0; 
  Student obj;   
  ifstream readfile("New.dat",ios::binary);
  
  cout&lt;&lt;"Enter Roll # of student";       
  cin&gt;&gt;a;
  
  while(!readfile.eof())
  {
      readfile.read((char *) &amp;obj, sizeof(obj));
  
      if(obj.getRoll()==a)
      {
          if(!readfile.eof())
          {
              pos=readfile.tellg();  
              obj.show();
              cout&lt;&lt;"PLease Enter New Details of Student \n";
              obj.get();
              readfile.close();                
              ofstream file("New.dat",ios::binary);
              file.seekp(pos);
              file.write((char*)&amp;obj,sizeof(obj));  
              cout&lt;&lt;"Student Record Has Been Updated \n";
              countt=1;
          }
      }
  }
  
  file.close();
  </code></pre>