Boost C++ Libraries: Ticket #9968: [filesystem] Streams don't handle unicode file name on Windows https://svn.boost.org/trac10/ticket/9968 <p> I want to read / write a file with a unicode file name using boost filesystem, boost locale on Windows (mingw). </p> <p> This is my code: </p> <p> #include &lt;boost/locale.hpp&gt; #define BOOST_NO_CXX11_SCOPED_ENUMS #include &lt;boost/filesystem.hpp&gt; #include &lt;boost/filesystem/fstream.hpp&gt; namespace fs = boost::filesystem; </p> <p> #include &lt;string&gt; #include &lt;iostream&gt; </p> <p> int main() { </p> <blockquote> <p> std::locale::global(boost::locale::generator().generate("")); fs::path::imbue(std::locale()); </p> </blockquote> <blockquote> <p> fs::path file("äöü.txt"); if (!fs::exists(file)) { </p> <blockquote> <p> std::cout &lt;&lt; "File does not exist" &lt;&lt; std::endl; </p> </blockquote> <p> } </p> </blockquote> <blockquote> <p> fs::ofstream(file, std::ios_base::app) &lt;&lt; "Test" &lt;&lt; std::endl; </p> </blockquote> <p> } </p> <p> The fs::exists really checks for a file with the name äöü.txt. But the written file has the name äöü.txt. </p> <p> Reading gives the same problem. Using fs::wofstream doesn't help either, since this just handles wide input. </p> <p> So it seems the behaviour of fs::ofstream is off. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9968 Trac 1.4.3 anonymous Sun, 08 Mar 2015 16:53:22 GMT <link>https://svn.boost.org/trac10/ticket/9968#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9968#comment:1</guid> <description> <p> Same problem here, I tried also utf8 and it doesn't work as well: </p> <pre class="wiki">#include &lt;boost/filesystem/detail/utf8_codecvt_facet.hpp&gt; (...) std::locale global_loc = std::locale(); std::locale loc(global_loc, new boost::filesystem::detail::utf8_codecvt_facet); boost::filesystem::path::imbue(loc); (...) boost::filesystem::ofstream hello("שלום.txt"); </pre><p> it creates ラゥラ慵勉・txt since I'm on SJIS encoding. </p> <p> Windows machine, i686-w64-mingw32-g++ (GCC) 4.8.3 on Cygwin </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Sun, 08 Mar 2015 16:55:01 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9968#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9968#comment:1</guid> <description> <p> Same problem here, I tried also utf8 and it doesn't work as well: </p> <pre class="wiki">#include &lt;boost/filesystem/detail/utf8_codecvt_facet.hpp&gt; (...) std::locale global_loc = std::locale(); std::locale loc(global_loc, new boost::filesystem::detail::utf8_codecvt_facet); boost::filesystem::path::imbue(loc); (...) boost::filesystem::ofstream hello("שלום.txt"); </pre><p> it creates ラゥラ慵勉・txt since I'm on SJIS encoding. </p> <p> Windows machine, i686-w64-mingw32-g++ (GCC) 4.8.3 on Cygwin </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Artyom Beilis</dc:creator> <pubDate>Wed, 07 Oct 2015 15:16:56 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9968#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9968#comment:2</guid> <description> <p> The problem is that boost::filesystem::ofstream uses native filebuf - and mingw does not support wide path parameter so basically it fails back to narrow strings. </p> <p> In these terms ofstream is not really useful under mingw. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 22 May 2017 14:43:04 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9968#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9968#comment:3</guid> <description> <p> Still an issue in 1.63. </p> <p> Workaround: Create a temporary file with a normal name (file.tmp) and use </p> <p> boost::filesystem::copy_file("file.tmp", destfile) </p> <p> That is a major nuisance, though. </p> </description> <category>Ticket</category> </item> <item> <author>boost.flamefire@…</author> <pubDate>Mon, 25 Sep 2017 02:28:15 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9968#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9968#comment:4</guid> <description> <p> Came across the same problem. I was wondering: If boost has to fall back to narrow character set on mingw then why doesn't it convert the filename correctly? </p> <p> In my case I have to write to the user directory but the username contains an umlaut. Internally I use all UTF8 in the string (std::string) and also have the path as an UTF8 string. When I pass it to e.g. memory mapped files or the directory functions it works. In MSVC it also works (widechar open function for fstream) but on MinGW it falls back to narrow char open and (maybe?) passes the utf8 string raw into the open function instead of converting it to the system encoding. </p> </description> <category>Ticket</category> </item> </channel> </rss>