c++ minizip解压文件的方法是什么

avatar
作者
猴君
阅读量:0

在C++中使用minizip库解压文件的方法如下:

#include "unzip.h"  int main() {     unzFile zipFile = unzOpen("example.zip");     if (zipFile == NULL) {         printf("Error opening zip file\n");         return 1;     }      unz_file_info fileInfo;     char filename[256];     unzGetCurrentFileInfo(zipFile, &fileInfo, filename, sizeof(filename), NULL, 0, NULL, 0);      if (unzLocateFile(zipFile, filename, 1) != UNZ_OK) {         printf("File not found in zip\n");         unzClose(zipFile);         return 1;     }      if (unzOpenCurrentFile(zipFile) != UNZ_OK) {         printf("Error opening current file\n");         unzClose(zipFile);         return 1;     }      FILE* outFile = fopen(filename, "wb");     if (outFile == NULL) {         printf("Error creating output file\n");         unzCloseCurrentFile(zipFile);         unzClose(zipFile);         return 1;     }      char buffer[4096];     int bytesRead;     while ((bytesRead = unzReadCurrentFile(zipFile, buffer, sizeof(buffer))) > 0) {         fwrite(buffer, 1, bytesRead, outFile);     }      fclose(outFile);     unzCloseCurrentFile(zipFile);     unzClose(zipFile);      return 0; } 

在上面的示例中,我们使用minizip库打开了一个zip文件,然后解压了其中的文件到当前目录。您可以根据自己的需求修改文件路径等参数。

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!