For example, there is a 1 GB file.
How to get a piece of data somewhere in the middle without reading it completely?
Use family functions *seek . If you are using the old, generic way to read files ( fopen , 'fread`), then use the fseek function. This function receives three parameters — the first — the file descriptor, the third — the “rewind” method — from the beginning, from the current position, or from the end. And the second parameter indicates how many bytes to "rewind". Also paired to her function ftell , which returns the current position.
If you use work through stream (fstream), then the seekg function is needed .
Source: https://ru.stackoverflow.com/questions/230822/
All Articles
fseek()(C ++seekg()) there is no difference between text files and binary files. There is no nix in the world *. These files only in the programmer’s head differ in some way. In Windows, indeed, there are differences at the level of data conversion when reading and writing. When reading a text file, the Ctrl-Z character is perceived as the end of the file, and the sequence of 2 characters"\r\n"is replaced with one'\n'. When writing a text file, each character'\n'is replaced with the sequence"\r\n". - avp