title: Code not working for "Modifying a data in a Binary file"
body: <p>So this is my code to "Modify a record from a binary file", and it should work...</p>
  
  <pre><code>void Update()
  {
      fstream file;
  
      STUDENT st, temp; // STUDENT is a class which I made
  
      int RollNo;
      clrscr();
      cout &lt;&lt; "Enter the Roll Number: ";
      cin &gt;&gt; RollNo; // to get the roll number which is to be modified. Also there is a data member inside the class STUDENT which is also known as RollNo
  
      cout &lt;&lt; "\n Enter the update info...\n\n";
      st.Input(); // This is a function inside the class STUDENT to get the values for the data members
  
      file.open("Student.dat", ios::binary | ios::ate);
      file.seekg(0);
  
      while(file)
      {
          file.read((char*)&amp;temp, sizeof(temp)); // the data which is being read is stored inside temp
  
          if(temp.retRollNo() == RollNo) // since RollNo is a private data member inside the class STUDENT so I've created an accessor function which returns RollNo
          {
              file.seekp(file.tellg() - sizeof(temp));
              file.write((char*)&amp;st, sizeof(st));
          }
      } // please note that this loop modifies all the instances which match the criteria and not just one since this while loop runs until end of file
  
      file.close();
  }
  </code></pre>
  
  <p>But the problem with this code is that it does not modifies any record... Why?</p>