Opening fstream with file with Unicode file name under Windows using non-MSVC compiler

后端 未结 3 520
暗喜
暗喜 2020-12-10 14:30

I need to open a file as std::fstream (or actually any other std::ostream) when file name is \"Unicode\" file name.

Under MSVC I have non-standard e

相关标签:
3条回答
  • 2020-12-10 15:08

    Unfortunately, there's no standard way to do that, although C++0x (1x?) promises to do that. Until then, you properly assumed that a solution can be found in Boost, however, the library you're searching for is Boost.Filesystem.

    Boost.Filesystem internally uses wide strings by default for its universal path system, so there are no unicode problems in this regard.

    0 讨论(0)
  • 2020-12-10 15:17

    Convert the Unicode filename to a char* string using something like wcstombs() or WideCharToMultiByte() (which gives you far more control over the codepages involved).

    Then use the converted filename to open the file.

    0 讨论(0)
  • 2020-12-10 15:21

    Currently there is no easy solution.

    You need to create your own stream buffer that uses _wfopen under the hood. You can use for this for example boost::iostream

    0 讨论(0)
提交回复
热议问题