Click to See Complete Forum and Search --> : replace word
supertech
September 27th, 2004, 08:40 PM
if line is read from a file and is,
string line = "weather,is,cold";
how to replace word "cold" with "hot" and write it back to same line
in same file?. ->"weather,is,hot";
using seekp()??
kuphryn
September 27th, 2004, 10:20 PM
Given that the word you want to replace is <= length than what you want to replace, one solution is file-mapping. Otherwise, you generally you have to use a temp file.
Kuphryn
jfaust
September 27th, 2004, 11:39 PM
Another option is to use the external utility sed. It's been ported to nearly everything. If you haven't used sed, you haven't lived.
Another is to read the whole file in, replacing as you go, and then write it back out. This is probably identical to using a temp file for small files.
Jeff
HighCommander4
September 28th, 2004, 03:02 PM
For small files, I find it most convenient to re-write the entire file, as others suggested already.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.