|
-
September 27th, 2004, 08:40 PM
#1
replace word
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()??
-
September 27th, 2004, 10:20 PM
#2
Re: replace word
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
-
September 27th, 2004, 11:39 PM
#3
Re: replace word
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
-
September 28th, 2004, 03:02 PM
#4
Re: replace word
For small files, I find it most convenient to re-write the entire file, as others suggested already.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|