Boost logo

Boost Users :

Subject: Re: [Boost-users] Open a filename with a wstring or wchar_t *
From: PB (newbarker_at_[hidden])
Date: 2010-08-02 17:21:47

On Mon, Aug 2, 2010 at 9:39 PM, Bo Jensen <jensen.bo_at_[hidden]> wrote:
> On Mon, Aug 2, 2010 at 8:32 PM, Timothy Madden <terminatorul_at_[hidden]> wrote:
>> Bo Jensen wrote:
>>> On Mon, Aug 2, 2010 at 2:03 PM, Timothy Madden <terminatorul_at_[hidden]>
>>> wrote:
>>>> Bo Jensen wrote:
>>>>> I use :
>>>>>  typedef boost::filesystem::wpath SlmWPath;
>>>>>  typedef boost::filesystem::wfstream SlmWfstream;
>>>>>  typedef boost::filesystem::wofstream SlmWOfstream;
>>>>>  typedef boost::filesystem::wifstream SlmWIfstream;
>>>> Yes, I can create wide streams, what I want is to pass a wide string as
>>>> the
>>>> file name to be opned.
>>> This should work :
>>> boost::filesystem::wfstream test;
>>> The above typedefs was just to show the tools you need from booost
>>> filesystem.
>> Oh, yes, you are right !
>> It must be the 'Additions to <fstream>' thing, that construct an ifstream
>> from a filesystem::path/wpath. Actually I do not even have a wchar_t * in my
>> program, I use a wpath ! :)
> I don't know all the details, but on windows I think filenames is only
> utf-16. On linux you should be safe, what ever locale you use. I would
> be interested to hear how it worked out.

We had a program compiling under Microsoft Visual Studio 2003 that was
running in different regions around the world and allowing users in
their regions to open their files ok. This program deals at the char*
level, working with strings encoded using local code pages.

When we upgraded to Microsoft Visual Studio 2008, this failed to work
on std::ofstream/std::ifstream because Microsoft changed some
internals of the runtime library. To fix this (I think we should've
been doing this all along anyway!) we needed to issue a
std::setlocale(LC_CTYPE,"") call at program startup so that the
runtime library internally knew how to convert the char* to a wide
character string. The runtime library uses mbstowcs() to convert that
char* to a wchar_t* which needs to know the code page.

If the program was Unicode we wouldn't have faced the issue above.


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