title: Rename function doesn't work, using c++
body: <p>This is the code snippet which i had written:</p>
  
  <p>I am using <strong>turbo c++</strong> (because I'm studying in India); <strong>my problem is written in a comment</strong>.</p>
  
  <pre><code>void Sort()
      {
          ofstream Change("temp.dat",ios::binary);
          ifstream RData("Student.dat",ios::in|ios::binary);
          Student S[1000];
          int q=0;
          while(RData.read((char*)&amp;S[q],sizeof(Student)))
              q++;
          int w=0;
          Student temp;
          for(int e=0;e&lt;q-w;++e)
              for(w=0;w+1&lt;q;++w)
                  if(strcmp(S[w+1].accnm(),S[w].accnm())&lt;0)
                  {
                      temp=S[w+1];
                      S[w+1]=S[w];
                      S[w]=temp;
                  }
          w=0;
          while(!Change.eof()&amp;&amp;w&lt;q)
          {
              Change.write((char*)&amp;S[w],sizeof(Student));
              w++;
          }
          cout&lt;&lt;"\nSorted";
          cout&lt;&lt;"\nWould you like to add a record to the sorted records\nsuch that the records remain sorted?(y/n)(case sensitive)\n";
          if(getche()=='y')
          {
              e=0;
              Change.seekp(0);
              if(q==999){cout&lt;&lt;"No more records can be added .You can rewrite records by the insert option in menu.";return;}
              temp.insdata();
              for(w=0;w&lt;q;w++)
                  if(strcmp(S[w].accnm(),temp.accnm())&lt;0&amp;&amp;!e)
                      Change.write((char*)&amp;S[w],sizeof(Student));
                  else
                  {
                      Change.write((char*)&amp;temp,sizeof(Student));
                      Change.write((char*)&amp;S[w],sizeof(Student));
                      e=1;
                  }
          }
          remove("Student.dat");
          rename("temp.dat","Student.dat");//doesn't rename
          Change.close();
          RData.close();
      }
  </code></pre>
  
  <p>No error shown by compiler but it doesn't rename the file but it removes the file</p>
  
  <p>Thanks</p>