Modify files in C++

C

carmaski

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
 
V

Victor Bazarov

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
 
C

carmaski

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,049
Members
47,654
Latest member
LannySinge

Latest Threads

Top