There is a binary file, logically divided into several parts. The problem is that I do not want to load all the information into RAM, and the fopen() function only allows appending data to the file. My own requests may be, for example, such: write the following data to a file from the 512th byte to the 1024th ...

How can I change the data in the file? How can I move a file if I know the position I need in it?

PS The project is implemented in VC ++

    1 answer 1

    If you are working through FILE , then the functions ftell (returns the current position in the file) and fseek (sets the current position) will help you. Get on the 512th byte and write what you need.

    PS Standard functions, not only for VC ++.

    • Can I edit an existing file? - Koshachok
    • You can overwrite parts of a file. Open it as "r+b" . - Harry
    • Ie just setting the pointer to the position I need, and just using fwrite with the key r + b, will I replace the bits with the ones I need? - koshachok
    • Listen, well, after all, simply by asking Google to "get to the right position in the C ++ file" you get the second item on C / C ++: working with files (stdio.h) - well, at least do a little work yourself! If you chew everything and put it in your mouth - it will not be your program ... - Harry