C ++读缓冲区大小 [英] C++ reading buffer size

查看:156
本文介绍了C ++读缓冲区大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设此文件为2和1/2块长,块大小为1024。

Suppose that this file is 2 and 1/2 blocks long, with block size of 1024.

aBlock = 1024;
char* buffer = new char[aBlock];
while (!myFile.eof()) {
    myFile.read(buffer,aBlock);
    //do more stuff
}

第三次读取将写入一半的缓冲区,另一半有无效数据。有没有办法知道它实际写入缓冲区有多少字节?

The third time it reads, it is going to write half of the buffer, leaving the other half with invalid data. Is there a way to know how many bytes did it actually write to the buffer?

推荐答案

istream :: gcount 返回上一次读取的字节数。

istream::gcount returns the number of bytes read by the previous read.

这篇关于C ++读缓冲区大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆