Easiest way is to read file line-by-line into a container such as a vector. Make whatever changes you want to the vector. Then save the contents of the vector back to the file.
There are other ways, such as reading from one file and writing to a different file, with no need for a vector. Than at the end, delete the original file and rename the new file to give it the old name.