ifstream::read 不告诉它真正读取了多少字节?
ifstream::read doesn't tell how many bytes it really reads?
我正在使用ifstream::read
读取一个文件,
ifstream ifs("a.txt");
char buf[1024];
ifs.read(buf, 1024);
但是.txt的大小可能小于1000 bytes
,那么我怎么知道从ifs
读取了多少字节呢?
您可以使用std::ifstream::gcount
:获取上次操作提取的字符数
ifstream ifs("a.txt");
char buf[1024];
ifs.read(buf, 1024);
size_t extracted = ifs.gcount();
或
ifstream ifs("a.txt");
char buf[1024];
size_t extracted = ifs.read(buf, 1024).gcount();
因为CCD_ 5返回CCD_。
相关文章:
- 理解boost::asio-async_read在无需读取内容时的行为
- 使用新行和不使用新行读取文件
- 读取文件并输入到矢量中
- 用c++从输入文件中读取另一行
- 读取文件的最后一行并输入到链接列表时出错
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 无法找到/读取配置文件.conf-FileIOException
- 复制列表初始化的隐式转换的等级是多少
- 如何使用Luacneneneba API正确读取字符串和表参数
- C++将文本文件中的数据读取到结构数组中
- 如何用 c++ 读取 txt 文件,如果我们不知道其中有多少个数据字符串,以及每行有多长?
- 尝试创建一个读取.txt文件,显示它,计数唯一单词的程序,并在使用了多少次的情况下显示独特的单词.C
- 一个文件被读取了多少
- 从 exe 文件中读取的整数是多少
- ifstream::read 不告诉它真正读取了多少字节?
- 正在读取一个布尔原子以及它需要多少个周期
- C++ 中有多少个方法逐个字符读取字符串,以对每个字符执行所需的操作
- ifstream:: ifstream可以读取的最大文件大小是多少?
- 如何在不知道一行文本有多少元素的情况下读取每个元素?(c++)
- C++(使用 <windows.h> 的串行通信) - 我如何事先知道 ReadFile() 方法将读取多少个字符