- #include "stdafx.h"
- #include "zlib.h"
- #include <iostream>
- using namespace std;
- #pragma comment(lib,"zlib.lib")
- int _tmain(int argc, _TCHAR* argv[])
- {
- int err;
- Byte compr[200], uncompr[200]; //足够大
- uLong comprLen, uncomprLen;
- const char* hello = "1234567890"; //原文
- uLong len = strlen(hello);// + 1;
- comprLen = sizeof(compr) / sizeof(compr[0]);
- err = compress(compr, &comprLen, (const Bytef*)hello, len);
- if (err != Z_OK)
- {
- cerr << "压缩错误: " << err << 'n ';
- }
- cout << "原文长度: " << len << "
压缩后长度:" << comprLen << 'n ';
- strcpy((char*)uncompr, "garbage ");
- err = uncompress(uncompr, &uncomprLen, compr, comprLen);
- if (err != Z_OK)
- {
- cerr << "解压错误: " << err << 'n ';
- }
- cout << "
原文长度:" << len << "
解压后长度:" << uncomprLen << 'n ';
- if (strcmp((char*)uncompr, hello))
- {
- cerr << "
解压失败!!!
";
- }
- else
- {
- cout << "
解压成功:" << (char*)uncompr;
- }
- FILE *f= fopen("d:\b1.bin","wb");
- fwrite(compr,comprLen,1,f);
- fclose(f);
- getchar();
- return 0;
- }
相关热门文章
给主人留下些什么吧!~~
评论热议