473,395 Members | 1,675 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,395 software developers and data experts.

File Content Modification

Dear C++'ers

I like to know how we can modify the contents in a file

ex: There is a file.txt

with the following data

Weather=Cold
WhatIDo=SleepOntheBed

to be replaced with

Weather=Sunny
WhatIDo=GoToBeach

The seekp function able to replace the contents but it also
eliminating the further contents in the buffer. Is there any way we
read only one line of the file ata time, adjust the size of this line
to fit the new contents.
For my application putting all the file contents in an array is not
feasible.

Hope I am clear
Waiting for ur replies
Cheers
P

Apr 12 '07 #1
3 1809
On 12 Apr, 13:01, "Tinku" <Praveen.Boi...@gmail.comwrote:
Dear C++'ers

I like to know how we can modify the contents in a file

ex: There is a file.txt

with the following data

Weather=Cold
WhatIDo=SleepOntheBed

to be replaced with

Weather=Sunny
WhatIDo=GoToBeach

The seekp function able to replace the contents but it also
eliminating the further contents in the buffer. Is there any way we
read only one line of the file ata time, adjust the size of this line
to fit the new contents.
For my application putting all the file contents in an array is not
feasible.
An alternative is to open a second, temporary file, to which you write
the changes and when done replace the original file with the temporary
one.

--
Erik Wikström

Apr 12 '07 #2
Tinku wrote:
Dear C++'ers

I like to know how we can modify the contents in a file

ex: There is a file.txt

with the following data

Weather=Cold
WhatIDo=SleepOntheBed

to be replaced with

Weather=Sunny
WhatIDo=GoToBeach

The seekp function able to replace the contents but it also
eliminating the further contents in the buffer. Is there any way we
read only one line of the file ata time, adjust the size of this line
to fit the new contents.
For my application putting all the file contents in an array is not
feasible.
It would be easy if all the lines were the same length ! Remember the
80 column text files from IBM mainframe days ?

OK, so maybe not.

An alternative is to rewrite the entire file.
Apr 12 '07 #3
On Apr 12, 2:01 pm, Gianni Mariani <gi3nos...@mariani.wswrote:
Tinkuwrote:
Dear C++'ers
I like to know how we can modify the contents in a file
ex: There is a file.txt
with the following data
Weather=Cold
WhatIDo=SleepOntheBed
to be replaced with
Weather=Sunny
WhatIDo=GoToBeach
The seekp function able to replace the contents but it also
eliminating the further contents in the buffer. Is there any way we
read only one line of the file ata time, adjust the size of this line
to fit the new contents.
For my application putting all the file contents in an array is not
feasible.

It would be easy if all the lines were the same length ! Remember the
80 column text files from IBM mainframe days ?

OK, so maybe not.

An alternative is to rewrite the entire file.
Thanks all for replying me...

I missed one important requirement.
I have to modify lines randomly in the file by taking those particular
lines as parameters. There is one nasty function doing this stuff. It
scans the file until that line has reached and try to adjust the file
pointer to the appropriate position and modify the content there. So
using a temp file could not be a feasible solution to my problem as
only one global file has to be maintained throughout the software
run.

I like to know if there is a way to read one line at a time (ex:
getline()) modify it and put the new content into this line without
disturbing the content in the next line. Any suggestions/ ideas in
this direction will be very much appreciated.

Thanking you

Cheers
Apr 13 '07 #4

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

Similar topics

13
by: Daniel Mueller | last post by:
Hello Fellow Python Programmers, I have the following problem: i want to read the content of a file every 10 seconds. now what is the best funktion to do that? to open the file, read it and...
22
by: Long | last post by:
Problem: to insert the content of a file in an HTML document at a specific location. One possible way is to add a WebCharm tag like this: <%@charm:text 20 0 my_include_file.txt %> When the...
6
by: Omid | last post by:
Hi. I have problems when I try to redirect everything that is sent to cout to a file. I have one piece of code that works and one that does not work. The only difference is which headers I use....
2
by: CJ | last post by:
I've got following: > file_a content needs to be compared with file_b content. I want to write content in binary form, then run a line by line comparison on characters. When the first different...
3
by: Jesper. | last post by:
Hi, Once I heard something about a files checksum. Is there a smart way to verify to some degree that the content of a file has not been changed in C#. best regards Jesper.
9
by: Jay Kim | last post by:
Hi, We're implementing a Windows application using Visual Basic .NET. One of the key features we need to implement is that we should be able to get the accurate byte offset of user selected...
1
by: Henry Law | last post by:
(I posted this to comp.infosystems.www.browsers.misc but there seems to be very little traffic there. I can't see another suitable group; is it on topic here? If not, any suggestions as to...
2
dmjpro
by: dmjpro | last post by:
suppose i open a file in write mode. if the file exists then the new content will be overwritten and the file opened in append mode then the exsiting file content will be appended. can't i do...
9
by: richee | last post by:
Hi all, I am new to Perl but see that it offers some fantastic opportunities and am trying to use it more in problem solving but could do with a little help on a problem thats driving me nuts.......
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
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...
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...

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.