C++ 文件压缩以处理c++;
我想压缩我的程序的中间输出(用C++),然后将其解压缩。您可以使用Boost IOStreams来压缩数据,例如,沿着以下几行将数据压缩/解压缩到文件中或从文件中解压缩(示例改编自):C++ 文件压缩以处理c++;,c++,C++,我想压缩我的程序的中间输出(用C++),然后将其解压缩。您可以使用Boost IOStreams来压缩数据,例如,沿着以下几行将数据压缩/解压缩到文件中或从文件中解压缩(示例改编自): 为什么不使用zlib的可能副本?轻便、高效、应用广泛,这对我们很有帮助。如何提供要压缩的文件而不是文本的位置?Thanks@user1309369你能澄清一下吗?是否有要压缩的现有文件?或者?我想压缩一个现有的文件,然后在需要原始格式时将其解压缩。 #include <fstream> #includ
为什么不使用zlib的可能副本?轻便、高效、应用广泛,这对我们很有帮助。如何提供要压缩的文件而不是文本的位置?Thanks@user1309369你能澄清一下吗?是否有要压缩的现有文件?或者?我想压缩一个现有的文件,然后在需要原始格式时将其解压缩。
#include <fstream>
#include <iostream>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>
namespace bo = boost::iostreams;
int main()
{
{
std::ofstream ofile("hello.gz", std::ios_base::out | std::ios_base::binary);
bo::filtering_ostream out;
out.push(bo::gzip_compressor());
out.push(ofile);
out << "This is a gz file\n";
}
{
std::ifstream ifile("hello.gz", std::ios_base::in | std::ios_base::binary);
bo::filtering_streambuf<bo::input> in;
in.push(bo::gzip_decompressor());
in.push(ifile);
boost::iostreams::copy(in, std::cout);
}
}
std::ifstream ifile("file", std::ios_base::in | std::ios_base::binary);
std::ofstream ofile("file.gz", std::ios_base::out | std::ios_base::binary);
bo::filtering_streambuf<bo::output> out;
out.push(bo::gzip_compressor());
out.push(ofile);
bo::copy(ifile, out);