best way to modify a file

D

dornick

Is there any way to do this without simply rewriting the entire file
with the changes? I was thinking of using fstream, since it can handle
input and output, but couldn't figure out exactly how to do it.

Suggestions?

Thanks,
dornick
 
D

DHOLLINGSWORTH2

dornick said:
Is there any way to do this without simply rewriting the entire file
with the changes? I was thinking of using fstream, since it can handle
input and output, but couldn't figure out exactly how to do it.

Suggestions?

Thanks,
dornick
You can open a file to "rw", which will allow you to make changes. However,
if you are inserting text, then the portion of the file occuring after the
change would be over written. AS long as you are replacing say a char with
a different char this is ok. Otherwise you will need to read ahead of your
write, and re-write the intire end of the file.
 
L

Larry Brasfield

DHOLLINGSWORTH2 said:
You can open a file to "rw", which will allow you to make changes. However, if you are inserting text, then the portion of the
file occuring after the change would be over written. AS long as you are replacing say a char with a different char this is ok.
Otherwise you will need to read ahead of your write, and re-write the intire end of the file.


That suggestion should be followed with some
caution and a caveat. For characters that are
not subject to line-boundary translations, it
will work. But if the stream is opened in text
mode, (usually the default), be aware that for
each such character written, more than one
byte could be written and that for each such
character overwritten with a plain character,
the result could be the plain character value
followed by a portion of the line-boundary
sequence used on the system.

For those reasons, I would tend to not try
to exploit the suggestion.
 
D

dornick

Thanks for the suggestion. I am, in fact, only trying to replace
individual characters. If you don't mind, could you give me a few
lines of code to show me exactly how to pull this off? I would be very
grateful.

dornick
 
D

Default User

dornick said:
Thanks for the suggestion. I am, in fact, only trying to replace
individual characters. If you don't mind, could you give me a few
lines of code to show me exactly how to pull this off? I would be very
grateful.


Would you mind quoting a reasonable portion of the post to which you
are replying, so that people can tell:

1. Who you are addressing
2. What you are talking about

I would be very grateful. To do this via Google, click "show options"
and use the Reply found there, NOT the one at the bottom of the post.



Brian
 
L

Larry Brasfield

Read about the "fseek()", "lseek()", and "seek()" in the C runtime,
or the "seekpos()" and "seekoff()" members of std::basic_filebuf
in the C++ standard library.

I presume you are not concerned about rewriting
characters that may become, or already be, line
boundary characters.
Would you mind quoting a reasonable portion of the post to which you
are replying, so that people can tell:

1. Who you are addressing
2. What you are talking about

I would be very grateful. To do this via Google, click "show options"
and use the Reply found there, NOT the one at the bottom of the post.

Most newsreader tools have a thread view, aka
"Group by Conversation" in MS Outlook Express.
This relies upon the "References" and "Message-ID"
fields to show what post is in reply to what.

That said, selective quoting is a real courtesy.
 
D

Default User

Most newsreader tools have a thread view, aka
"Group by Conversation" in MS Outlook Express.
This relies upon the "References" and "Message-ID"
fields to show what post is in reply to what.

And many people using those newsreaders have their options set to show
only new messages. It's ridiculous to require people to go back and
read old message to figure our what someone is talking about.
That said, selective quoting is a real courtesy.

It's more than a courtesy, it's been the standard of usenet for a long
time. I have no idea what got into the Google people that they screwed
this up so badly.


Brian
 
D

dornick

Default said:
Would you mind quoting a reasonable portion of the post to which you
are replying, so that people can tell:

1. Who you are addressing
2. What you are talking about

I would be very grateful. To do this via Google, click "show options"
and use the Reply found there, NOT the one at the bottom of the post.



Brian


Thanks for the help. I guess Google had me spoiled with all their
"conversation" views and I forgot some people would have no context for
my post.
 
D

Default User

dornick said:
Default User wrote:

Thanks for the help. I guess Google had me spoiled with all their
"conversation" views and I forgot some people would have no context for
my post.


You're welcome, and thank you for understanding.



Brian
 

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
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top