如何在C ++中读取/写入压缩后的文件? [英] How do I read / write gzipped files in C++?

查看:191
本文介绍了如何在C ++中读取/写入压缩后的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何用C ++读取/写入压缩后的文件?

How do I read / write gzipped files in C++?

iostream包装器类此处看起来不错,这是一个简单的用法示例:

The iostream wrapper classes here look good, and here is a simple usage example:

gz::igzstream in(filename);
std::string line;
while(std::getline(in, line)){
  std::cout << line << std::endl;
}

但是我实际上无法链接它(尽管我有一个/usr/lib/libz.a).一个简单的

But I wasn't able to actually link it (although I have a /usr/lib/libz.a). A simple

g++ test-gzstream.cpp -lz

没有做(undefined reference to gz::gzstreambase::~gzstreambase()).

推荐答案

很明显,您还需要cpp文件,其中也定义了gzstreambase析构函数,即

Obviously you need the cpp-file where the gzstreambase destructor is defined as well, i.e. gzstream.cpp (that's the link fault). libz is just a c-api for gzip, it knows nothing of c++ stdlib streams.

Boost的iostream库也具有gzip和bzip2流.

Boost's iostream lib has gzip and bzip2 streams too.

更新了链接,以指向包含重大错误修复的最新代码.

Updated the link to point to the latest version of the code that includes a major bug fix.

这篇关于如何在C ++中读取/写入压缩后的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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