Boost logo

Boost Users :

Subject: Re: [Boost-users] Open a filename with a wstring or wchar_t *
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2010-08-03 06:12:24

On 02/08/10 15:02, Timothy Madden wrote:
> Mathias Gaunard wrote:
>> On 02/08/10 12:46, Timothy Madden wrote:
>>> Hello
>>> Surprisingly enough, C++ file-based streams can be opened with a char *
>>> string (for the filename) only, while modern computer systems have
>>> Unicode filenames.
>> All of them but Microsoft Windows support UTF-8.
> How would I let the file-stream object know that the filename to be
> opened is encoded in UTF-8 ?

It is assumed to be in the locale of the system.
Most POSIX systems use a UTF-8 locale these days, but if you really want
to be portable, you should convert that.

> How ?
> If user enters an Unicode filename (with Korean characters) for me to
> open, and the current locale is Latin 2, how would I open the file ?

On Windows, convert from UTF-8 to wide characters when calling system calls.
On other operating systems, pass UTF-8 to the system calls, or convert
them to the locale if you care enough about non-utf8 locales.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at