[英]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. 例如,拥有10个字节的文件,并读取第5个字节。
是的,使用istream :: seekg寻找你想要读取的位置,然后istream :: get读取一个字节(或istream :: read读取多个字节)。
Yes, fseek
and fgetc
will do exactly this. 是的,
fseek
和fgetc
就是这样做的。
http://www.cplusplus.com/reference/clibrary/cstdio/fseek/ http://www.cplusplus.com/reference/clibrary/cstdio/fseek/
http://www.cplusplus.com/reference/clibrary/cstdio/fgetc/ http://www.cplusplus.com/reference/clibrary/cstdio/fgetc/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.