tags:

views:

43

answers:

2

Hi i want to overwrite the content(object) in a specific file i have set the position but it always add to the end of the file

Code

 int InputIO::editPatient(int location,Obj P){

        int positon=location*sizeof(P);
        f.open("File.dat",ios::in|ios::out|ios::app|ios::binary|ios::ate);
        f.seekp(0,ios::beg);
        f.seekp(positon,ios::cur);
        f.write((char*)&P,sizeof(Movie));
        f.close();

        return 0;



        }
+1  A: 

Just solve this have to remove ios::app (Append) Append always add to the end of the file

Sudantha
+3  A: 

Don't use the ios::app flag (which stands for append). When you use this flag, it prevents you from reading or writing any of the content that was present in the file before you opened it -- you can only add new content to the end (and since you opened in read+write mode, you can re-read what you wrote and rewrite it, but you still can't get to the data before it).

Adam Rosenfield