Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

file

byte

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.

like image 785
0x77D Avatar asked Feb 25 '12 16:02

0x77D


1 Answers

Yes, fseek and fgetc will do exactly this.

http://www.cplusplus.com/reference/clibrary/cstdio/fseek/

http://www.cplusplus.com/reference/clibrary/cstdio/fgetc/

like image 174
StilesCrisis Avatar answered Sep 28 '22 06:09

StilesCrisis