c++ - 逐行读取输入数据 gzipped 文件

标签 c++

我知道有些人已经写过关于这个问题的文章;然而,这个问题我还不清楚。我需要读取包含未格式化数据的压缩文件。我没有成功地尝试遵循 zlib 和 gzstream 站点的说明。有人能给我提供一个如何使用 ifstream 直接从压缩的 gzip 文件中提取数据的快速示例吗?我使用 dat 文件的过程如下:

#include <iostream>
#include <sstream>
#include <string>

int main () {
    ifstream file;
    string stringtemp;
    stringstream line2convert;
    file.open("directory/file.dat");
    // read each line using a for loop (I know the total number of lines)
    file.getline (line,100);
    // extract information line by line using stringstreams
    line2convert  << line;
    line2convert >> int2convert;   
    ...
    ...
    ...
} 

有人可以给我提示添加我需要的几行吗?

谢谢! -F

最佳答案

如果你知道如何在 gzstream 中链接,你就可以做到

只需将“ifstream”替换为“igzstream”

.

关于c++ - 逐行读取输入数据 gzipped 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7781796/

相关文章:

c++ - 显示描述文本 (WINAPI)

c++ - 将 vector 大小连接到字符串

c++ - 与 bash 命令行相比,rsync 与 QProcess 的运行方式不同

C++:如何将多个对象复制到剪贴板并在之后提取它们?

c++ - 轻量级 C++ Gui 库

c++ - 在 Qt 中声明元类型的问题

c++ - 并行化带来的性能损失

c++ - 如何在 C++ 中正确使用 setfill()?

c++ - 什么时候不调用重写的虚函数

c++ - 特化 std::make_shared