gpt4 book ai didi

c++ - C++中的压缩文件IO

转载 作者:搜寻专家 更新时间:2023-10-31 01:54:13 26 4
gpt4 key购买 nike

我有一个模拟,我需要在代码运行时转储大量数据,通常约为 50GB 左右,这通常发生在几周左右。现在,我将数据导出为 legacy ASCII VTK 文件。

我想知道是否有任何方法可以在数据写入磁盘时对其进行压缩,以便节省一些空间(我需要同时运行多个版本的代码)。如果可能的话,我更喜欢标准库中的东西。

最佳答案

如果可以使用boost,看看zlib过滤器compressor and decompressor

#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++ - C++中的压缩文件IO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9980854/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com