在Windows范围内使用_wfopen
fopen
FILE *fp = fopen("newfile.txt", "rt+, ccs=encoding");
在当今情况下,情况要好一些,您不应修改minizip
的来源,但是在您的代码中仍然需要一个
#ifdef
在niCode。最新版本具有用于读/写zip的新API函数:
unzopen2_64(const voidPath,zlib_filefunc64_defpzlib_filefunc_def)zlib_filefunc64_def
zlib_filefunc64_def
我发现的第二个工作选项 - 只需将其设置为UTF -8即可。最好在应用程序初始化层进行操作,因为它不是线程安全的:
zipFile openZipFile(const std::string& utf8FilePath)
{
zipFile hZipFile = nullptr;
#ifdef WIN32
zlib_filefunc64_def ffunc;
fill_win32_filefunc64W(&ffunc);
// Convert path from UTF-8 to Unicode
const int count = MultiByteToWideChar(CP_UTF8, 0, utf8FilePath.c_str(), static_cast<int>(utf8FilePath.size()), NULL, 0);
std::wstring unicodePath(count, 0);
MultiByteToWideChar(CP_UTF8, 0, utf8FilePath.c_str(), static_cast<int>(utf8FilePath.size()), &unicodePath[0], count);
hZipFile = zipOpen2_64(unicodePath.c_str(), 0, NULL, &ffunc);
#else
// Unix systems handles path in the UTF-8 by default
hZipFile = zipOpen64(utf8FilePath.c_str(), 0);
#endif
return hZipFile;
}
它看起来要简单得多,但是我认为第一个变体是更好和可靠的,因为它不取决于语言环境的设置。