问题描述
我想用 C++17 重构这段代码。在这种情况下,我可以使用 std::filesystem 吗?
#if defined(BOOSTER_WIN_NATIVE)
bool open(std::string const &file_name,std::string const &encoding)
{
close();
//
// Under Windows,we have to use "_wfopen" to get
// access to paths with Unicode in them.
//
// As not all standard C++ libraries support nonstandard std::istream::open(wchar_t const *)
// we would use good old stdio and _wfopen CRTL functions.
//
std::wstring wfile_name = conv::to_utf<wchar_t>(file_name,encoding);
file = _wfopen(wfile_name.c_str(),L"rb");
return file!=0;
}
#else // POSIX systems do not have all this Wide API crap,as native codepages are UTF-8
// We do not use encoding as we use native file name encoding
bool open(std::string const &file_name,std::string const &/* encoding */)
{
close();
file = fopen(file_name.c_str(),"rb");
return file!=0;
}
#endif
utf8 utf16 的转换我已经改过了,但是好像没有这个价值了。
std::wstring wfile_name;
typedef std::codecvt_utf8_utf16<wchar_t> codec;
std::wstring_convert<codec> converter;
wfile_name = converter.from_bytes(file_name);
file = _wfopen(wfile_name.c_str(),L"rb");
return file != 0;
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)