Lets say I have a csv and want to first output data to the third cell and then go back and and post data to the first cell is this possible ? View the short example for more clarification below. Thanks!
1 2 3
// open the file for output etc
outputfile << "," << "," << "3rd cell";
// now how can I go back and output something to the first or second cell after skipping the first two cells in the line above?
No, it's not possible, especially with text files, unless you have pre-allocated a fixed amount of blank or otherwise overwritable space for the data.
Files are usually written sequentially except in specific cases (for example, there is a 4-byte space reserved in a WAV file format (binary file) where you can write the size of the data stream, this lets you write the size of the data stream after you calculate the data stream, but again you need to already know you allocated 4 bytes in advance).
Do all the necessary logic first, then write to the output stream. This is easier to maintain anyway than what you're suggesting.
Hold on guys. The data of a csv file uses a ',' as a delimiter. Right? Couldn't you create a function that reads the data from the csv and stores it into a vector and also use a comma to move on to the next element of the vector? Say a vector of strings. The csv cell 1 would be vector[0] and so on. Then if you wanted to modify cell 2 for example, you could modify vector[1]. Then before closing the file stream you would write all the data from your vector back into the csv. Something like that maybe?
Okay thank you everyone. And manga I think that would work but with the size of my actual program something like that wouldn't work, atleast for my application :)