Sign in to follow this  
freeworld

file i/o is it possible to replace chunks of text without rewritting the whole file

Recommended Posts

in C++ is it possible to replace one or more word(s) without having to rewrite the whole file? The way I would do it now is read in the whole text file to a vector of strings, rewrite what I wanted into the strings then write it all back to the text file. Is that the proper way of doing it? Speed isn't an issue, just want it to be clean and flexible.

Share this post


Link to post
Share on other sites
That's the proper way (details notwithstanding), yes.

The limitation isn't really a language one, but an OS one: files simply don't work the way you'd like them to. The goal is to be able to write everything in one continuous chunk on the HD, so if the replacement text is a different length from what it's replacing, everything would get messed up.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this