My actual problem is much larger but figuring out how to do this example will help me. I want to overwrite data that already exists in a text file but I can't seem to do this.
ex.
[file.txt]
I have five fingers.
My current code:
ofstream File;
File.open("file.txt", ios:ut);
File.seekp(8, ios::beg);
File << "four";
File.close();
I have tried different combinations of ios on the second line, but it either
a) erases the whole file and writes "four" at the begining or end
b) writes "four" at the very end ("I have five fingers.four")
c) erases the whole file and writes "four" eight characters into the file
I know I can get it to work by reading in the file and going through it word by word, then re-outputting the right words and replace then at the correct time, but the actual file is extremely large so processing the whole file is not an option.
Assuming I know the starting byte locations of everything I want to change, byte 8 in this case, how can I get the file.txt to display this:
I have four fingers
Is there any way to do this and avoid using ios::binary? I've tried changing File << "four"; to File.write("four", 8); but it just writes "four" eight characters into the file and nothing else is there. Thanks