is there any way this can be done? I've looked at the help files and
checked out as many tutorials as i could find on the net (as always) but no
joy.
thanks 8 3287
Stewart wrote: is there any way this can be done? I've looked at the help files and checked out as many tutorials as i could find on the net (as always) but no joy.
What does "alter without overwriting" mean?
"Stewart" <rs********@blu eyonder.co.uk> wrote in message
news:Yk******** **********@fe1. news.blueyonder .co.uk... is there any way this can be done? I've looked at the help files and checked out as many tutorials as i could find on the net (as always) but no joy.
thanks
If you mean inserting or removing pieces of a file, then the answer is no.
Files (in any language) don't work like that.
john
ah - sorry for the lack of clarity in my last post. it was pretty late when
i worte this and i was really tired from trying to solve this prob.
what i meant was suppose i had a text file with a string like:
"halo 2 is out on 11th novemeber"
now if i were to move the file poitner along a bit and insert some text
(let's say "asgujdsgf" ) then, you'd have something like this as a result:
halo 2 is out on 11asgujdsgfber
what I WANT to do is insert a string into the text in a text file, without
overwriting the pre-existing text, like this:
"halo 2 is out on 11th asgujdsgnovemeb er"
is this at all possible?
thanks again
Stewart wrote: ah - sorry for the lack of clarity in my last post. it was pretty late when i worte this and i was really tired from trying to solve this prob.
what i meant was suppose i had a text file with a string like: "halo 2 is out on 11th novemeber"
now if i were to move the file poitner along a bit and insert some text (let's say "asgujdsgf" ) then, you'd have something like this as a result: halo 2 is out on 11asgujdsgfber
what I WANT to do is insert a string into the text in a text file, without overwriting the pre-existing text, like this: "halo 2 is out on 11th asgujdsgnovemeb er"
is this at all possible?
Right... No. File streams are essentially a mapping of file contents on
your external storage. AFAIK, no external storage allows "insertions "
except perhaps a very particular ones (a stack of punch-cards, maybe?).
So, since in general there is no support for insertions, ofstream, being
a generic file stream, doesn't have any mechanism in it either.
V
ah i see. thanks for your help victor
"Stewart" <rs********@blu eyonder.co.uk> wrote in message
news:ND******** *********@fe2.n ews.blueyonder. co.uk... ah - sorry for the lack of clarity in my last post. it was pretty late when i worte this and i was really tired from trying to solve this prob.
what i meant was suppose i had a text file with a string like: "halo 2 is out on 11th novemeber"
now if i were to move the file poitner along a bit and insert some text (let's say "asgujdsgf" ) then, you'd have something like this as a result: halo 2 is out on 11asgujdsgfber
what I WANT to do is insert a string into the text in a text file, without overwriting the pre-existing text, like this: "halo 2 is out on 11th asgujdsgnovemeb er"
is this at all possible?
thanks again
The standard method is to read the file in, writing out to a new file all
the text up to the "insertion point", then writing out the text you're
inserting, then writing out the rest of the file. (But you're writing to a
different file, you understand. You can always rename the file(s), of
course, so that it looks like you're writing to the "same" file.)
-Howard
"Howard" <al*****@hotmai l.com> wrote in message
news:EP******** ***********@bgt nsc05-news.ops.worldn et.att.net... "Stewart" <rs********@blu eyonder.co.uk> wrote in message news:ND******** *********@fe2.n ews.blueyonder. co.uk... ah - sorry for the lack of clarity in my last post. it was pretty late when i worte this and i was really tired from trying to solve this prob.
what i meant was suppose i had a text file with a string like: "halo 2 is out on 11th novemeber"
now if i were to move the file poitner along a bit and insert some text (let's say "asgujdsgf" ) then, you'd have something like this as a
result: halo 2 is out on 11asgujdsgfber
what I WANT to do is insert a string into the text in a text file,
without overwriting the pre-existing text, like this: "halo 2 is out on 11th asgujdsgnovemeb er"
is this at all possible?
thanks again
The standard method is to read the file in, writing out to a new file all the text up to the "insertion point", then writing out the text you're inserting, then writing out the rest of the file. (But you're writing to
a different file, you understand. You can always rename the file(s), of course, so that it looks like you're writing to the "same" file.)
One possible approach for single file implementation would be:
- copy string to circular buffer
- open and io stream for read/write
- find insertion point in io stream
- loop while !eof
- read char from stream
- push back char to buffer
- (over)write char to stream from front of circular buffer
- pop front
- loop while !buffer.empty()
- write char to stream from front of circular buffer
- pop front
Any comments from those more familiar with streams? Performance relative to
other methods would certainly need to be measured. I could see using this
approach when inserting relatively small string near the tail of a very
large file.
Jeff F
yeah it looks like i'll have to do summat like that. thanks a lot for all
of your help. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Brandon McCombs |
last post by:
This may be the wrong group but I didn't see anything for VC++ so I'm
trying here.
I have a C++ book by Deitel and Deitel that says I can use fstream
File("data.dat", ios::in | ios::out | ios::binary) to declare a file
object with read/write modes turned on for working with binary data.
I've tried this and my file is not created. The only time it is created
is when I specify ifstream or ofstream but not fstream. I've tried
removing the...
|
by: August1 |
last post by:
A handful of articles have been posted requesting information on how
to use these functions in addition to the time() function as the seed
to generate unique groups (sets) of numbers - each group consisting of
6 numbers - with a total of 50 groups of numbers.
A well-known girl that some publishing companies use to provide
introductory level textbooks to various Junior Colleges in the U.S.,
not surprisngly, asks for this same exact...
|
by: Gactimus |
last post by:
Here is a program that encodes and decodes a text file. What I need to do
is write a C++ program that requests 3 different file names. One filename
is for the source file to be encoded, another is the name of the 'encoded'
output file, and the final filename is an offset file. On a character by
character basis, the program needs to look at the first character of the
source file and offset it by the first character in the offset file. The...
|
by: idesilva |
last post by:
Hi,
I have an app that generates a text log at a very high rate. Currently
I use an ofstream object to write the log. I would like to control when
'exactly' the log is written to the disk. Also I want to be able to
reset the buffer contents without writing them to the disk file.
- Can the 'buffer size' of an ofstream object (in fact, any iostream
lib object) be controlled?
- Can we control *when* the buffer is flushed?
|
by: keweiming |
last post by:
I have a project which needs to open hundreds to thousands of files for
writing. The following is a simplified test program I wrote to see if I
can use a map<string, ofstream> object to keep the list of ofstreams. I
need to have them open simultaneously for writing -- I have millions of
rows of data to write to them so opening and closing all the time will
be unacceptable in efficiency.
The following program compiles but failed to run....
| |
by: Paul LAURENT |
last post by:
Hi everybody,
I am using the STL "ofstream" class.
I open a file using "ofstream" in update at the end mode ("ate"), I can read and
write my file correctly.
=> What I would like to do is deleting some lines from the file which decreases
the size of the file.
|
by: adamrobillard |
last post by:
Hi,
I have always used fopen and FILE* to load and save structures to file.
I am trying to convert all the older code to use proper C++ calls...
the following code works properly but I would like to know if I am
using the fstream methods properly. (as long as I am cleaning up I
might as well do it right). By the way, this is just a bogus example
with a structure, values and filename for demonstration purposes.
PS-> I have a funny...
|
by: Serge Rielau |
last post by:
Hi all,
Following Ian's passionate postings on problems with ALTOBJ and the
alter table wizard in the control center I'll try to explain how to use
ALTOBJ with this thread. I'm not going to get into the GUI because it is
hard to describe in text.
First of all what is the purpose of ALTOBJ()?
This procedure was created mostly for ISVs who need to do produce change
scripts to upgrade application from release to release, but it can also
|
by: true911m |
last post by:
This is a simple walkthrough to get PyInstaller up and running.
I decided to give PI a try, because it claims to be more selective about what it bundles into its executable files by default, and it also integrates UPX (Ultimate Packer for eXecutables) into the build process, if you have it installed. It also claims functionality on linux, as a bonus (I didn't test this). I highly recommend the UPX options, and will cover how to get it...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |