|I hope this helps. It's from the site that I almost always consult for for C++/STL details:
std::basic_ostream<CharT,Traits>::seekp - cppreference.com[^]
seekp lets you reposition the "cursor" in a read-write file (
ofstream) so you can overwrite characters starting at that point. But if your replacement isn't the same size as what you want to overwrite, you'll have to move the rest of the file up (if the replacement is shorter) or down (if the replacement is longer, in which case you have to do this first). It's usually easier to simply create a new file instead manipulating the original. This also preserves the original in case your software misbehaves.