1

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;



        }

2 Answers 2

6

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).

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.