微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

是否可以将 _wfopen 重构为 std::filesystem?

如何解决是否可以将 _wfopen 重构为 std::filesystem?

我想用 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 举报,一经查实,本站将立刻删除。