c++中如何使用gzip.compressString()函数

how to use gzip.compressString() function in c++

本文关键字:函数 compressString gzip 何使用 c++      更新时间:2023-10-16

如何使用chilkat使用gzip.compressstring()函数。语法是

bool CompressString(const char *inStr, const char *outCharset, CkByteData &outBytes);
// COMPRESSSTRING_END
// COMPRESSSTRINGTOFILE_BEGIN .but i dont know how to implement it in c++.

下面是我试图实现的代码,但没有成功

CkGzip gzip;
bool success;
CkByteData data;
char buffer[100] = {0};
success = gzip.CompressString("helloworld", "utf8", data);
data = buffer;
cout << buffer;
if (success != true) {
    printf("%sn", gzip.lastErrorText());
    return;
}

注意:我希望"hello world"以压缩形式输出

from Documentation link http://www.chilkatsoft.com/refdoc/vcCkGZipRef.html

bool CompressString(const char *inStr, const char *destCharset, CkByteData &outBytes);

Gzip压缩字符串并将输出写入字节数组。该字符串首先被转换为由destCharset指定的字符集。典型的字符集有"utf-8"、"iso-8859-1"、"shift_JIS"等。

成功返回true,失败返回false。

这意味着用户需要做这样的事情:Const char *instr = "test";const char *destCharset = "utf-8";//或"iso-8859-1", "shift_JIS"等CkByteData outBytes;//也可以通过new

在堆上分配

if (CompressString(inStr, destCharset, outBytes))数& lt; & lt;"成功 n";//现在用户可以戳到outBytes内部其他的cout & lt; & lt;"失败 n";