当我使用ifstream的read函数时,如何获得实际的字节数

How to get the real number of bytes when i use read function of ifstream

本文关键字:何获得 字节数 函数 ifstream read      更新时间:2023-10-16

代码:

ifstream in("a.jpg",ios:in|ios:binary);
char data[1024];
in.read(data,1024);

如何知道读取函数读取的实际字节数?

您想要使用gcount,类似于以下内容:

std::streamsize bytes_read = in.gcount();