我正在尝试使用 LibZip 在 C++ 中打开一个 zip 存档。因为我没有找到任何工作教程,所以我查阅了文档并找到了这段代码:
int err = 0;
zip_t *z = zip_open("file.zip", 0, &err);
zip_stat_t st;
zip_stat_init(&st);
cout << zip_stat(z, "file.zip", 0, &st) << endl;
cout << st.size << endl;
zip_close(z);
问题是 zip_stat 函数返回 -1 并且文件的大小为零。err 始终为 0,所以我不知道问题出在哪里。获取内容的代码如下所示:
char *contents = new char[st.size];
zip_file *f = zip_fopen(z, "file.zip", 0);
zip_fread(f, contents, st.size);
zip_fclose(f);
delete[] contents;
但显然我还不能测试这部分代码。我正在使用 C++ 14 和 LibZip 1.5.2