0
我正在使用標頭zip.hpp
(可以在這裏找到https://markand.bitbucket.io/libzip/index.html或這裏http://hg.markand.fr/libzip/file)壓縮一些文件。Cpp強制使用libzip編寫zip
之後要刪除原始文件,我使用remove("myfile.txt")
。
顯然,zip.hpp
在運行結束時將文件壓縮,因此它找不到該文件並且不創建zip文件夾。如果我遺漏了remove("myfile.txt")
,一切正常,除了我有幾個文件飛來飛去,我只想在他們的壓縮形式。
您對如何強制libzip寫入zip文件有任何想法嗎? 如果我刪除了archive
-instance我所期望的,它應該強制創建,但顯然libzip::Archive
-class沒有析構函數(至少我無法找到一個和delete archive
拋出許多錯誤)
我基本的代碼如下所示:
#include <fstream>
#include <zip.h>
#include "lib/zip.hpp"
int main() {
libzip::Archive archive("output.zip", ZIP_CREATE);
std::ofstream outfile ("myfile.txt");
outfile << "Hello World\n";
outfile.close();
archive.add(libzip::source::file("myfile.txt"), "myfile2.txt");
// delete archive; // throws an error...
// remove("myfile.txt");
// if left out, output.zip gets created otherwise nothing is created
return 0;
}
多數民衆贊成在輝煌,爲什麼我沒有想到的範圍?非常感謝! – David