Reputation: 1574
Is it possible to open a file and reading an only byte at a certain position without having to load all the file into an array?
For example, having a file of 10 bytes, and reading the 5th.
Upvotes: 6
Views: 10308
Reputation:
Yes, use istream::seekg to seek to the position you want to read from, and then istream::get to read a byte (or istream::read to read more than one byte).
Upvotes: 10
Reputation: 16310
Yes, fseek
and fgetc
will do exactly this.
http://www.cplusplus.com/reference/clibrary/cstdio/fseek/
http://www.cplusplus.com/reference/clibrary/cstdio/fgetc/
Upvotes: 9