473,406 Members | 2,371 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,406 software developers and data experts.

text file indexing

in VC++ Express Edi

Is their a way to replace one line of TEXT in an existing text file. I
now open it then
read in the data, once I have found somthing that needs updating, I
need to overwrite
that one line only and continue reading the rest of the file to check
for other line that
may need updates.

How can this be done with fstream.

I am reading about stream pointers but have not yet found anything on
overwriting a
line of text on an existing file.

If I could overwrite the line just after a getline was done that would
be great. Would need
to index -1 line write over the line and then would I need to index +1
lines for the next
getline?
Not sure how to do this.

any comments or suggestions about the issue.

Thanks

Feb 9 '06 #1
6 4804
electrixnow wrote:
in VC++ Express Edi
If you need VC++ specific solution, post to the VC++ newsgroup:
'microsoft.public.vc.language'. Here it doesn't not matter what
compiler/IDE you use, unless you're asking about a bug in the
compiler.
Is their a way to replace one line of TEXT in an existing text file.
If this is a question (questions usually end on a question mark), then
the answer is "yes, but it depends on your definition of 'one line'".
I
now open it then
read in the data, once I have found somthing that needs updating, I
need to overwrite
that one line only and continue reading the rest of the file to check
for other line that
may need updates.

How can this be done with fstream.
Again, if this is a question, then the answer is "just like with C
streams, you open one for reading, you open the other for writing, you
read one until you find the data you need replaced, you write all that
stuff before to the new stream, then you write the new data into the
output, then continue the copying after the data that needed to be
replaced".
I am reading about stream pointers but have not yet found anything on
overwriting a
line of text on an existing file.
Because it's not a functionality of a stream. It's an algorithm that
entirely depends on _your_ definition of "a line".
If I could overwrite the line just after a getline was done that would
be great.
What do you mean by that?
Would need
to index -1 line write over the line and then would I need to index +1
lines for the next
getline?
Not sure how to do this.


Another simple way is to read the whole file into a linked list of strings
(where each string is a "line"), then replace the string that contains the
"line" to be replaced with the new string, then write the whole list of
strings back to the file (or better to a newly created file).

V
--
Please remove capital As from my address when replying by mail
Feb 9 '06 #2
Thanks for the input. I have code that opens two files like you talked
about. Open the original for reading, then opens new file for write,
getline original, I use << to write to new. If any changes are needed
in the data, then the new data is substituted to the new file for that
line.

What at really want to do is open the text file for read/write, use
getline for text.
Evaluate the line for changes, If any, and just change the line or data
in the line
at that point. After that I would use getline to eval the next line of
text in file. That way
I would only have the original file open and would not have to create a
second.

Thanks

Feb 9 '06 #3
electrixnow wrote:
Thanks for the input. I have code that opens two files like you talked
about. Open the original for reading, then opens new file for write,
getline original, I use << to write to new. If any changes are needed
in the data, then the new data is substituted to the new file for that
line.

What at really want to do is open the text file for read/write, use
getline for text.
Evaluate the line for changes, If any, and just change the line or data
in the line
at that point. After that I would use getline to eval the next line of
text in file. That way
I would only have the original file open and would not have to create a
second.


You have the original file like this (4 "lines" separated by, say, '\n'):
---------------------
abc
defghijk
lmnopq
rstuvwxyz
---------------------
Now, you need to replace the second line with "111111111111111111111".
What's going to happen?

Or, you need to replace the second line with "123". What's the result?

Think about it.

V
--
Please remove capital As from my address when replying by mail
Feb 9 '06 #4
"electrixnow" <info...@charter.net> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
Thanks for the input. I have code that opens two files like you talked
about. Open the original for reading, then opens new file for write,
getline original, I use << to write to new. If any changes are needed
in the data, then the new data is substituted to the new file for that
line.

What at really want to do is open the text file for read/write, use
getline for text.
Evaluate the line for changes, If any, and just change the line or data
in the line
at that point. After that I would use getline to eval the next line of
text in file. That way
I would only have the original file open and would not have to create a
second.

Thanks


Works for binary files because the data is fixed length. That is, you could
open the file in binary mode (not using << for input) and replace the
characters "the" with "cat" because they are the same length. If, however,
you try to replace "the" with "gator" what will happen is the "or" will
overwrite the next 2 characters, whatever they happen to be. Of course you
could read the next 2 characters first and after the "or" write them, but
then they'd be overwritting characters, etc.. and you'd have to do that to
the end of the file.

Basically, if what you are replacing is not the same length as what is there
now, you open the file for input, and another file for output. Read from
input, write to output. That's the only easy way to change different length
data.
Feb 9 '06 #5
Thanks thats what I will do or have done.

Feb 9 '06 #6
electrixnow wrote:
What at really want to do is open the text file for read/write, use
getline for text.
Evaluate the line for changes, If any, and just change the line or data
in the line


As others have explained, you can do this OK if the replacement text is
the same size as the original. What happens if the replacement is not?

Well, in an ideal universe there would be a "insert_bytes( file, len )"
and a "delete_bytes( file, len )" or something. But such an operation is
not possible in any common file system as far as I know, and therefore
libraries don't have such a thing by default.
Feb 15 '06 #7

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

Similar topics

4
by: Peter Scott | last post by:
I created a table that has a column in that needs to contain a full Unix file path. Since 2048 was too long for a VARCHAR, I made it TEXT. I since populated the table. Now I want to make the...
0
by: SoftComplete Development | last post by:
AlphaTIX is a powerful, fast, scalable and easy to use Full Text Indexing and Retrieval library that will completely satisfy your application's indexing and retrieval needs. AlphaTIX indexing...
1
by: Perre Van Wilrijk | last post by:
Hi, I've got a full text index which works fine, SQLSERVER2000/WIN 2000 SERVER. The system requires to update indexes immediately, so I use a timestamp field to enable this. No problems so...
60
by: Julie | last post by:
What is the *fastest* way in .NET to search large on-disk text files (100+ MB) for a given string. The files are unindexed and unsorted, and for the purposes of my immediate requirements, can't...
4
by: Vic Cekvenich | last post by:
What would be performance of pgSQL text search vs MySQL vs Lucene (flat file) for a 2 terabyte db? thanks for any comments. ..V -- Please post on Rich Internet Applications User Interface...
0
by: Chung Leong | last post by:
Here's a short tutorial on how to the OLE-DB extension to access Windows Indexing Service. Impress your office-mates with a powerful full-text search feature on your intranet. It's easier than you...
3
by: Chung Leong | last post by:
Here's the rest of the tutorial I started earlier: Aside from text within a document, Indexing Service let you search on meta information stored in the files. For example, MusicArtist and...
14
by: mfrsousa | last post by:
hi there, i have a huge large text file (350.000 lines) that i want to import to a MS Acccess Database, of course i don't want to use Access, but do it with C#. i already have tried the...
0
by: rclark30 | last post by:
Hello to everyone out there. I am a non SQL person TRAPPED in a nightmare! The long short is we have a CRM 3.0 database that is running in SQL 2005 on a Windows 2003 SP1 Server. (HP ProLiant ML350...
1
by: Server Applications | last post by:
Hello I am trying to build a system where I can full-text index documents with UTF8 or UTF16 data using Oracle Text. I am doing the filtering in a third-party component outside the database, so...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.