0

I need to do the following in a .csv file using a c++ code
1. open the file
2. read the first line...extract the number part of it
3. enter the user entered data at the end of the file (append)
4. now add the extracted integer and a certain user inoutted integer and replace the number part of the first line with this new integer.

I have done the most of it...what remains is how to replace the first line?

3
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by rdrast
0

I have done the most of it...what remains is how to replace the first line?

There are two options:

1.
- read the original file in your memory.
- delete the file
- create a new file and add your line
- add all the lines in memory

2.
- rename the original file
- open a new file and add your line
- open the original and write the lines to the new file

0

there has to be a better way then deleting (or creating copies of ) the old file completely every time you need to amend something in it.

0

there has to be a better way then deleting (or creating copies of ) the old file completely every time you need to amend something in it.

Nope, there isn't, unless you are using absolute fixed-length fields, and 99% of the time, a .csv file does not have fixed length fields.

If you want to change a value in the first line, you read the file, modify the first line, and write it out again.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.