fstream.read 进度指示器
fstream.read progress indicator
我尝试创建一个进度指示器来读取C++中的文件。我面临的问题是
-
tellg()
和tellp()
在读取时都只返回 24 或 -1,即使文件的大小约为 400MB 编辑:从线程中读取文件 tellg() 返回正确的值 - 我不是在使用循环读取文件,而是使用单个
read
指令
代码(简体):
fstream file;
void readFile(string filename)
{
file.open(filename, ios::in | ios::binary);
file.read((char*) &buffer, buffersize);
}
void readFileWithProgressIndicator(string filename)
{
size_t filesize = getFileSize(filename)
thread file_read(readFile, filename);
for( ; ; )
{
cout << file.tellg() << ":" << file.tellp() << endl;
}
file_read.join();
}
1-程序行为似乎是连贯的。看起来您刚刚通过 1 次调用读取了您的文件,我想您的缓冲区大小为 24。你能检查一下吗?
2-提案
std::atomic<std::streampos> fg;
std::atomic<std::streampos> fp;
void readFile(string filename)
{
fstream file;
file.open(filename, ios::in | ios::binary);
file.read((char*) &buffer, buffersize);
fg=file.tellg();
fp=file.tellp();
}
void readFileWithProgressIndicator(string filename)
{
size_t filesize = getFileSize(filename)
thread file_read(readFile, filename);
for( ; ; )
{
cout << fg << ":" << fp << endl;
}
file_read.join();
}
相关文章:
- 使用 ImageIO.read() 生成的图像是否仍然使用传递给它的相同内存?
- std::ifstream::read 不会读取所有 512 字节,并设置 EOF 和失败位
- write() 和 read() 中几乎没有混淆
- C++ TCP 套接字通信 - 连接按预期工作,几秒钟后失败,没有收到新数据,read() 和 recv() 块
- 为什么调试器引发"read access violation. this was nullptr"异常?
- 对同一文件使用 .read 的次数是否有限制?
- Win32 API - HWND "{unused = ???} Unable to read memory"错误
- 为什么我会"Invalid read of size 8"?(瓦尔格林德)
- QDataStream read to QVector
- asio::read() 需要很长时间,使用 asio::write 没有问题
- Read OpenCV Mat 16bit to QImage 8bit Greyscale
- 如果 I/O read() 处于阻塞阶段,如何使用 Ctrl+C 退出 C++ 程序?
- 如何将 (serverClients[i].read() 传递给 ESP8266 上的字节数组
- 将 Lora.read() 转储到数组
- 无法通过 FUSE 文件系统"read"任何内容
- 指向 std::unrodered_map 中元素的指针返回'Read access violation'
- 封送指向结构异常"cannot Read or Write protected memory"的指针数组的指针数组
- C++HTTP客户端在GET请求后挂起read()调用
- 从带有 std::ifstream::read() 的文件中读取 int 遍历 char * 二进制数据
- fstream.read 进度指示器