annidy / notes

0 stars 0 forks source link

ghc-filesystem #309

Open annidy opened 4 months ago

annidy commented 4 months ago

C++标准文件系统在17以后支持,不过如果你在Windows上开发,我更推荐使用 https://github.com/gulrak/filesystem ,因为它对宽字符支持的更好,并且文件读写也有兼容。

Windows上字符集是一个遗留很多年的大坑 #51 ,想要正确在UTF8和宽字符间转换,就要用到Windows的系统API,且正确实现也不容易。ghc提供了一个可用的版本,用起来很方便

安装这个库推荐用vcpkg

vcpkg install ghc-filesystem

转换函数没有公开到文档,但是还是可以调用的

#include <ghc/filesystem.hpp>

char *pUtf8 = ghc::filesystem::detail::toUtf8(L"你好");
wchar_t *pStr = gch::filesystem::detail::toWChar(pUtf8);