0

I'd like to insert some content between my textfile. So, I did this by using seekp()

But If I insert the content, it's not added to the existing content.The inserted contents are replaced existing content. How do we solve these problem?

ex) aaaaaa insert bbb at 3 I want ->aaabbbaaa using seekp() -> aaabbb

vikash singh
  • 1,479
  • 1
  • 19
  • 29
Thanos
  • 1
  • 3
    You cannot. You will need to rewrite everything that comes after the bbb. – Botje Nov 22 '19 at 12:37
  • 1
    Generally speaking, writing to an existing file overwrites, it doesn't insert to make room for additional content. To do what you want, the usual technique (assuming you want to all content of the original file, plus an insertion) is to copy data from your original file to a copy until the insertion point, insert any new content into the copy, copy remaining data from the original to the copy, the delete the original and rename the copy to the original. – Peter Nov 22 '19 at 12:39

0 Answers0