On Apr 12, 2:01 pm, Gianni Mariani <gi3nos...@mariani.wswrote:
Tinkuwrote:
Dear C++'ers
I like to know how we can modify the contents in a file
ex: There is a file.txt
with the following data
Weather=Cold
WhatIDo=SleepOntheBed
to be replaced with
Weather=Sunny
WhatIDo=GoToBeach
The seekp function able to replace the contents but it also
eliminating the further contents in the buffer. Is there any way we
read only one line of the file ata time, adjust the size of this line
to fit the new contents.
For my application putting all the file contents in an array is not
feasible.
It would be easy if all the lines were the same length ! Remember the
80 column text files from IBM mainframe days ?
OK, so maybe not.
An alternative is to rewrite the entire file.
Thanks all for replying me...
I missed one important requirement.
I have to modify lines randomly in the file by taking those particular
lines as parameters. There is one nasty function doing this stuff. It
scans the file until that line has reached and try to adjust the file
pointer to the appropriate position and modify the content there. So
using a temp file could not be a feasible solution to my problem as
only one global file has to be maintained throughout the software
run.
I like to know if there is a way to read one line at a time (ex:
getline()) modify it and put the new content into this line without
disturbing the content in the next line. Any suggestions/ ideas in
this direction will be very much appreciated.
Thanking you
Cheers