可以看一下我的Github項目,使用封裝zlib庫的ZLibString類進(jìn)行壓縮C++字符串。
- 使用
將ZLibString.h,ZLibString.cpp文件加入項目,使用以下方法進(jìn)行壓縮,解壓縮。
// 壓縮,pcContentBuf:要壓縮的內(nèi)容 pcCompBuf:壓縮后的內(nèi)容 ulCompLen:得到壓縮后的長度
bool Compress(const char* pcContentBuf, char* pcCompBuf, unsigned long& ulCompLen);
// 解壓,pcCompBuf:壓縮的內(nèi)容, pcUnCompBuf:解壓后的內(nèi)容 ulCompLen:傳入壓縮內(nèi)容的長度
bool UnCompress(const char* pcCompBuf, char* pcUnCompBuf, unsigned long ulCompLen);
```
具體見源碼。