Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > "Insert" (not append) new text segment to an existing text file

Reply
Thread Tools

"Insert" (not append) new text segment to an existing text file

 
 
sm
Guest
Posts: n/a
 
      04-29-2005
How to "Insert" (not append) new text segment to an existing text file?

Assume that we have text file as shown below;
Elvis
Sofia
Kylix
BCB--> How to insert here?
Atten
BuilderX
Roma
Together
Cairo
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      04-29-2005
sm wrote:
> How to "Insert" (not append) new text segment to an existing text file?
>
> Assume that we have text file as shown below;
> Elvis
> Sofia
> Kylix
> BCB--> How to insert here?
> Atten
> BuilderX
> Roma
> Together
> Cairo


This has nothing to do with the language. Open the file for reading,
open another file (new one) for writing. Begin reading the first one
and writing to the new one until you hit the spot where you need to
insert something. Now, write what you need inserted. Once done, go
on with "copying" the contents of the original file. Another possible
solution is to read the entire contents of the file into some memory
structure, insert what you need into that structure, then write that
structure out to the same file again (after re-opening it for writing).

V
 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      04-29-2005
sm wrote:

> How to "Insert" (not append) new text segment to an existing text file?


You cannot insert new data into the file. You can replace existing data with
new data (as long as the size stays the same), and you can append, but you
cannot add or remove data at any other place than the end.
If you need that, you basically have to copy the whole contents of the file
over to a new file, inserting the new data at the right place. Then rename
it back to the original file name.

> Assume that we have text file as shown below;
> Elvis
> Sofia
> Kylix
> BCB--> How to insert here?
> Atten
> BuilderX
> Roma
> Together
> Cairo


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing to text segment rahul C Programming 15 06-11-2008 09:37 PM
Existing Dll - using Functions from an existing dll Tristin.Colby@gmail.com Ruby 0 02-05-2008 07:38 PM
Why no existing Java type to existing XML schema binding support? nrm Java 3 04-10-2006 04:52 PM
question about const and text segment cppsks C++ 4 10-22-2004 06:40 PM
finding text-segment in a HTTP::Element tree Arthur B. Perl Misc 3 10-19-2003 11:44 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57