Find, Calculate, Replace a String in a File with c++

Hello Community,

i have a text file... with example following content:

Pizza 23232
Car 44,495
Drink 3493,90494
....
..
.

and so on..

no i want to find the 44,495 in this textfile.. calculate a new value like 44,495 x 2 + 5

and write the same file as

Pizza 23232
Car 93,99
Drink 3493,90494
....
..
.

back.. has anybody a ready programcode for that..

thanks for your time...
Read the data in from the file.
Change whatever you wish to.
Truncate the file.
Write all of the data back to the file.
Bear in mind that you can't have the behavior you see with text editors. When writing to a file you always overwrite what is already in the position you're writing to. AFAIK insertion and removal of data in the middle cannot be done directly, and modifying a chunk can be done without side effects only if the new chunk is of the same byte size of the old one (e.g. in this case you should write 93,990 or the last digit of the old string wouldn't be replaced and it would display 93,995).
Topic archived. No new replies allowed.