문자열을 압축하고 압축 된 길이를 비교해야합니다 (데이터의 중복성을위한 프록시 또는 대략적인 근사값으로 사용). Kolmogorov 복잡성). 현재 압축을 위해 boost :: iostreams를 사용하고 있습니다. 그러나 압축 된 데이터의 크기를 얻는 방법을 모르겠습니다. 누군가가 도와 줄 수 있니?boost :: iostreams에 의한 문자열의 압축 길이
코드 조각은
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/filesystem.hpp>
#include <string>
#include <sstream>
namespace io = boost::iostreams;
int main() {
std::string memblock;
std::cout << "Input the string to be compressed:";
std::cin >> memblock;
std::cout << memblock << std::endl;
io::filtering_ostream out;
out.push(io::gzip_compressor());
out.push(io::file_descriptor_sink("test.gz"));
out.write (memblock.c_str(), memblock.size());
std::cout << out.size() << std::endl;
return 0;
}
것입니까? 그렇다면 결과를 문자열로 얻고 그 길이를 얻는 것은 간단합니다. –