How to write to middle of a file in C++?

后端 未结 3 1315
北恋
北恋 2020-11-30 12:57

I think this should be quite simple, but my googling didn\'t help so far... I need to write to an existing file in C++, but not necessarily at the end of the file.

I

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 13:11

    You cannot insert in the middle of the file. You have to copy the old file to a new file and insert whatever you want in the middle during copying to the new file.

    Otherwise, if you intend to overwrite data/lines in the existing file, that is possible by using std::ostream::seekp() to identify the position within the file.

提交回复
热议问题