By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,418 Members | 1,084 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,418 IT Pros & Developers. It's quick & easy.

Modify files in C++

P: n/a
Hi,
I have worked with C++ off and on, but I am not sure how this must be
done. I need to modify some of the text in certain files. Specifically
I need to search for a certain word, and modify that word i.e. Change
it to some other shorter word.
I dont think that I can declare a buffer, because it may happen that
these files may be too big.

I hope someone has some ideas how this might be done.
Regards,
Rio

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
ca******@yahoo.com wrote:
I have worked with C++ off and on, but I am not sure how this must be
done. I need to modify some of the text in certain files. Specifically
I need to search for a certain word, and modify that word i.e. Change
it to some other shorter word.
I dont think that I can declare a buffer, because it may happen that
these files may be too big.

I hope someone has some ideas how this might be done.


The usual approach to this is to open your file for reading, open another
file for writing, start copying until you encounter the string you need
replaced, read the original, write the replacement, then proceed with your
copying until the source file is all copied. Then upon successful closing
of both files, rename (or delete) the original and rename the temporary
file so that it has the name of the original before the operation.

Nothing language specific in all this.

V
Jul 23 '05 #2

P: n/a
Thanks Victor. I was hoping if there were some better way of doing
this. Thank you for your help.
Regards,
Rio

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.