如何在C ++中逐行读取.gz文件? [英] How to read a .gz file line-by-line in C++?
本文介绍了如何在C ++中逐行读取.gz文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有.gz格式的3T文件。我想在C ++程序中逐行读取,而不是实际解压缩。任何人都可以发布一个简单的例子吗?
I have file of 3T in .gz format. I want to read it line-by-line in a C++ program without actually decompressing. Can any one post a simple example of doing it?
推荐答案
您最有可能需要使用ZLib的deflate,示例可以从网站
You most probably will have to use ZLib's deflate, example is available from their site
或者,您可以查看 BOOST C ++包装器
来自BOOST页面的示例数据从文件并写入标准输出)
The example from BOOST page (decompresses data from a file and writes it to standard output)
#include <fstream>
#include <iostream>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/zlib.hpp>
int main()
{
using namespace std;
ifstream file("hello.z", ios_base::in | ios_base::binary);
filtering_streambuf<input> in;
in.push(zlib_decompressor());
in.push(file);
boost::iostreams::copy(in, cout);
}
这篇关于如何在C ++中逐行读取.gz文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文