The easiest way would be to load the entire file into memory (like some sort of array of structs), change the bit of memory that you need to change, and then overwrite the file with what you have in memory.
Slightly more compilicated is to move the current location in the fstream to where you need it and then overwrite a piece of the file. To do this you need to know that the section you are overwriting already has enough space. In other words, you should not overwrite a 2 digit number with a number that has more digits. To get around this limitation you might consider using a binary file instead of a text file, but you would still need to be carefult about bit lengths. See functions like seekg, tellg, seekp, tellp, read, write, peek, and maybe a few others from http://www.cplusplus.com/reference/istream/iostream/
Another option is to use a memory mapped file, but I would recommend that you not pursue that option since you are asking this question.
Or you could write every line to a temp file and when your done searching and changing things when you exit, ask if you want to commit your changes which writes the temp file to the source file.