c++怎么解压文件 tar.zip gz格式等

c++怎么解压文件 tar.zip gz格式等 ( linux ) 能举个小例子吗 (zlib库?)

 #include <string>
#include <time.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include "zlib.h"
int main()
{
    unsigned long int fileLength;
    unsigned long int readLength;
    unsigned long int compressBufLength;
    unsigned long int uncompressLength;
    unsigned long int offset;

    unsigned char *readBuf = new unsigned char[512];//the readbuf of the exist file content
    unsigned char *compressBuf = new unsigned char[512];//the compress buffer   
    unsigned char *uncompressBuf = new unsigned char[512];//the uncompress  content buffer
    FILE *originalFile = fopen("/lgw150/temp/src/lg4/original.lg4","a+");//the exist file
    FILE *compressedFile = fopen("/lgw150/temp/src/lg4/compressed.lg4","a+");//compressfile
    FILE *uncompressFile = fopen("/lgw150/temp/src/lg4/uncompressed.lg4","a+");//

    fseek(originalFile,0,2);
    fileLength = ftell(originalFile);
    offset = 0;//
       while(offset <fileLength)//
    {


        printf("offset=%lu;fileLength=%lu\n",offset,fileLength);
        memset(readBuf,0,512);
        memset(compressBuf,0,512);
        memset(uncompressBuf,0,512);
        fseek(originalFile,offset,0);//
        readLength = fread(readBuf,sizeof(char),512,originalFile);
        offset += readLength;//
        int compressValue = compress(compressBuf,&compressBufLength,readBuf,readLength);
        int fwriteValue = fwrite(compressBuf,sizeof(char),compressBufLength,compressedFile);//
        printf("compressValue = %d;fwriteLength = %d;compressBufLength=%lu;readLength = %lu\n",compressValue,fwriteValue,compressBufLength,readLength);

        int uncompressValue = uncompress(uncompressBuf,&uncompressLength,compressBuf,compressBufLength);//
        int fwriteValue2= fwrite(uncompressBuf,sizeof(char),uncompressLength,uncompressFile);//
    }
    fseek(originalFile,0,0);
    fseek(compressedFile,0,0);
    fseek(uncompressFile,0,0);
    if(originalFile != NULL)
    {
        fclose(originalFile);
        originalFile = NULL;
    }

   if(compressedFile != NULL)
    {
        fclose(compressedFile);
        compressedFile = NULL;
    }
     if(uncompressFile != NULL)
    {
        fclose(uncompressFile);
        uncompressFile = NULL;
    }

    delete[] readBuf;
    delete[] compressBuf;
    delete[] uncompressBuf;
return 0;


}

http://blog.csdn.net/jiangyu912/article/details/7441270

直接用命令啊,tar xzvf xxx.tar.gz