C++ overwriting data in a file at a particular position

后端 未结 2 1574
旧时难觅i
旧时难觅i 2020-12-29 11:50

i m having problem in overwriting some data in a file in c++. the code i m using is

 int main(){
   fstream fout;
   fout.open(\"hello.txt\",fstream::binary         


        
2条回答
  •  青春惊慌失措
    2020-12-29 12:18

    The problem is with the fstream::app - it opens the file for appending, meaning all writes go to the end of the file. To avoid having the content erased, try opening with fstream::in as well, meaning open with fstream::binary | fstream::out | fstream::in.

提交回复
热议问题