Sign in to follow this  

fstream is being bad

This topic is 4760 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi i am trying to modify a text file that i created. i am using fstream to write. the text file looks like this. function { id = 1; name = blah; damage = 10; } what i am trying to do is to change what the variable equals, but when i do that this happens. function { id = 1; name = blah2;damage = 10; } or this. function { id = 1; name = Testingamage = 10; } i set the seek to the correct place but it overwrites the end of the line and it brings the bottom line up and starts to write over it. can any one help me so that doesent happen anymore. [Edited by - 31337noob on November 30, 2004 10:58:51 PM]

Share this post


Link to post
Share on other sites
Have you considered writing to a different file, by reading bits of the input, and outputting them (possibly modified according to the change you want to make)?

Share this post


Link to post
Share on other sites
You can't insert text into a file without overwriting other data. In your case, when you wrote "blah2;", it overwrote the six characters "blah;\n", so the newline got deleted. Similarly, when you wrote "Testing", it overwrote the seven characters "blah;\nd", resulting in the string "name = Testingamage = 10;" What you have to do is read in the input file, parse it, modify the variables, and rewrite it in its entirety. You cannot simply rewrite a little bit of it unless you are 100% sure the data occupies the exact same number of bytes.

Share this post


Link to post
Share on other sites

This topic is 4760 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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