Suppose my file a.txt has "ABC" written in it. Now I want to write a small b before capital B in the file. How will I do it. I've tried to do it but i'm having problems.
1. When opened in app mode seekp doesn't work.
2. When opened normally previous written data is erased.
You can only overwrite existing content in files or add more to the end of the file. If you want to insert in the middle, you have to rewrite everything after that point. The easiest way is as Aceix recommended: read it completely into a string, deal with the string, then write the string back to the file, overwriting the old contents.