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.
Then rewrite the whole thing again.
I mean,
-copy the content into your programme
-add b before B, maybe using std::string::find();
-write the editted stuff back to file.
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.