Whenever I try to write to a file, it automatically deletes what I have already written there. I have tried using ios::app to do so but then seekp(); doesn't work properly and I have not been able to find any relevant information on the web.
Also, I am using comma delimiters, if anyone also knows how to delete everything between two delimiters that would also be greatly appreciated.
So, basically, my problem is overwriting something between two delemiters, without overwriting the entire file.
Cheers
PS: If possible, simple syntax would be best. But it is better to have a difficult solution than no solution!!!
Okay, ios::ate will not work on a std::ofstream. For some reason it still wipes the file. One way to do this would be to open the stream for reading and writing. That should preserve the pre-existing data.
For your problem, though, this may not be enough. If you want to change data between two markers then you will run into problems unless the markers are a fixed distance apart. That is because writing always overwrites what is already there and does not insert and delete.
It may be better for you in that case to read the file in from a std::ifstream and write out to a new file the modified data using std::ofstream.
To solve this problem I created a new delimiter of a '?' between the 2 commas with which i wanted to change the information, i then used getline to read in everything up to the '?' and then used another getline to read the rest of the file.
In essence, what i have done is saved the whole file to separate variables and then copied over everything in the file using ofstream with the variables and new data
Thanks for your help everyone, in particular Galik, whose code is extremely useful and was required to input the '?' delimiter.