473,320 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

best way to modify a file

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

Jul 23 '05 #1
8 1986

"dornick" <do*****@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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.
Jul 23 '05 #2
"DHOLLINGSWORTH2" <DH*************@cox.net> wrote
in message news:zPoUd.18643$yr.3150@okepread05...
"dornick" <do*****@gmail.com> wrote in message news:11**********************@o13g2000cwo.googlegr oups.com...
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.

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.

--
--Larry Brasfield
email: do***********************@hotmail.com
Above views may belong only to me.
Jul 23 '05 #3
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

Jul 23 '05 #4

dornick wrote:
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

Jul 23 '05 #5
"Default User" <de***********@yahoo.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...

dornick wrote:
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.

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.

--
--Larry Brasfield
email: do***********************@hotmail.com
Above views may belong only to me.
Jul 23 '05 #6

Larry Brasfield wrote:
"Default User" <de***********@yahoo.com> wrote in message
Would you mind quoting a reasonable portion of the post to which you are replying

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

Jul 23 '05 #7

Default User wrote:
dornick wrote:
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

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.

Jul 23 '05 #8

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


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

Jul 23 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ezmeralda | last post by:
Hello, I have to solve the following task: - create an editor-application in c# to read, modify and create xml-files - .xsd-schema-file is available and can be used Currently, I am thinking...
29
by: Daniel Rudy | last post by:
Hello, Consider the following code fragment: fileptr = fopen(param->filename, "r"); if (fileptr == NULL) { error("digest.c: digest_file: Open File ", errno); return(-2); }
1
by: msnews.microsoft.com | last post by:
I'd like to hear your thoughts on best methods for populating drop down list controls. I have states and countries drop down lists that don't change often, so naturally I "hard code" them in the...
17
by: | last post by:
I have an app that retrieves data from an Access database. At the moment I have the SQL string as a Const in my app. I understand this is not best practice. I don't want the user to have access to...
2
by: John Granade | last post by:
I'm looking for the best way to make a dataset available from multiple Windows forms. The dataset is created from an XML file. I have a main form (frmMain) that loads the dataset and reads the...
11
by: Tom | last post by:
I am planning on adding a Preferences form to my application and using the Property Grid to display the preferences to the user. What do you think would be the best way to save these preferences...
8
by: robert | last post by:
Hello, I want to put (incrementally) changed/new files from a big file tree "directly,compressed and password-only-encrypted" to a remote backup server incrementally via FTP,SFTP or DAV.... At...
4
by: tshad | last post by:
I need to pass a few parameters to my Windows Service program. The end user will be changing the parameters and settings should be saved. What is the best practice - use app.config - use .ini...
7
by: =?Utf-8?B?UGhpbCBKb2huc29u?= | last post by:
Hello, I have an issue with some code I am updating: An entire file is loaded into a memory stream then that memory stream uses its WriteTo method to write to the responses output stream. ...
2
by: None | last post by:
We are creating a web application to be deployed to 150 of our customers to use as an interface to our software system. The web app needs to be completely customizable for our customers while...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.