Fstream removes N bytes from the end of a binary file

Is it possible to remove N bytes from the end of a binary in C ++ using fstream (or something similar)? I don’t want to read the whole file, cut it out and write it again, but since it is at the end of the file, it seems like this should not be such a problem.

Thanks for any advice.

+4
source share
2 answers

I don't know what a generic C ++ (platform independent) way to do this is without writing a new file. However, on POSIX systems (Linux, etc.) you can use the function ftruncate(). On Windows you can use SetEndOfFile().

, , fstream, /.

EDIT: Boost, resize_file() Filesystem, , .

+6

:

++ 17 resize_file

+1

Source: https://habr.com/ru/post/1525070/


All Articles