开发者

ifstream, bytes read?

开发者 https://www.devze.com 2022-12-14 23:25 出处:网络
How do you get how many bytes were read with the ifstream::read function? Tell is saying the file is 10 bytes and windows says it is 10 bytes too but there are only 8 bytes in the file so when I read

How do you get how many bytes were read with the ifstream::read function?

Tell is saying the file is 10 bytes and windows says it is 10 bytes too but there are only 8 bytes in the file so when I read it, it 开发者_StackOverflowis only reading the 8 bytes so I end up with too large of a buffer.


You can find out by calling gcount() on a stream immediately after you read.

ifs.read(buf, sizeof buf);
std::streamsize bytes = ifs.gcount();


There is a function called readsome(...) that does what you want:

streamsize readsome ( char* s, streamsize n );

Return Value The number of characters extracted.

0

精彩评论

暂无评论...
验证码 换一张
取 消