0

I am trying to take a a file of fixed size and use seekp to jump to a particular spot in the file, write around 100 bytes or so but only to that part of the file while still keeping the size of the total file the same and not losing the other data. As of right now it is adjusting the total size of the file to the size of the buffer but I dont want that to happen. Heres what I have so far, any help is appreciated.

int r = 2;
int size = 99;
char * buffer = new char(size);
    
fstream out;
out.open("C:\\Database\\2.bin", ios::out|ios::binary);
out.seekp((r-1)*100);
out.write(buffer, size+1);
out.close();
2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by cam875
0

Not sure I quite understand. Let's say the file contains "ABCEFGH". Now seek to there the 'E' appears and write "KLM". What result do you want
1) ABCKLMH
2) ABCKLMEFGH
3) something else

0

lets say I have a 1000 byte file and bytes 900-1000 are filled with data and I want to write to bytes 400-500, so I do that but everytime I do it resets the file size to 500 bytes killing the data farther in the file. I want to make it so it will write the new data to bytes 400-500 and keep the data at bytes 900-1000 while keeping the file size constant and not adjusting it therefore just updating part of the file with new data.

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.