1. 程式人生 > >C++----zlib 簡單的用法

C++----zlib 簡單的用法

簡單點,zlib是一種壓縮演算法,有 .h   .lib  檔案 ,我們可以直接使用

#include "stdafx.h"
#include "../zlib.h"
#pragma comment(lib,"../zlib.lib")

int main(int argc, char* argv[])
{
 unsigned char strSrc[]="hello world,aaaa bbbb cccc";
 unsigned char buf[1024]={0};
 unsigned char strDst[1024]={0};
 unsigned long srcLen=sizeof(strSrc);
 unsigned long bufLen=sizeof(buf);
 unsigned long dstLen=sizeof(strDst);

 printf("Src string : %s \n Length: %ld\n",strSrc,srcLen);

 /*壓縮*/
 compress(buf,&bufLen,strSrc,srcLen);
 printf("after compressed Length: %ld\n",bufLen);

 printf("compressed string %s\n",buf);
 /*解壓縮*/
 uncompress(strDst,&dstLen,buf,bufLen);
 printf("after uncompressed length: %ld\n",dstLen);

 printf("Uncompressed string %s\n",strDst);
 return 0;
}