0x77D
0x77D

Reputation: 1574

Reading a byte at certain position of a file in C++

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

Answers (2)

user784668
user784668

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

Related Questions