Boost logo

Boost :

Subject: Re: [boost] Silly Boost.Locale default narrowstringencodinginWindows
From: Peter Dimov (pdimov_at_[hidden])
Date: 2011-10-28 07:58:08


Alf P. Steinbach wrote:

> How do I make the following program work with Visual C++ in Windows, using
> narrow character string?
>
> <code>
> #include <stdio.h>
> #include <fcntl.h> // _O_U8TEXT
> #include <io.h> // _setmode, _fileno
> #include <windows.h>
>
> int main()
> {
> //SetConsoleOutputCP( 65001 );
> //_setmode( _fileno( stdout ), _O_U8TEXT );
> printf( "Blåbærsyltetøy! 日本国 кошка!\n" );
> }
> </code>

Output to a console wasn't our topic so far (and is not one of my strong
points), but the specific problem with this program is that the embedded
literal is not UTF-8, as the warning C4566 tells us, so there is no way for
you to get UTF-8 in the output. (You should be able to set VC++'s code page
to 65001, but I don't think you can.)

int main()
{
    printf( utf8_encode( L"кошка" ).c_str() );
}

This is not a practical problem for "proper" applications because Russian
text literals should always come from the equivalent of gettext and never be
embedded in code.

int main()
{
    printf( gettext( "cat" ).c_str() );
}

So, yes, I admit that you can't easily write a portable application (or a
command-line utility) that has its Russian texts hardcoded, if that's your
point. But you can write a command-line utility that can take кошка.txt as
input and work properly, which is what I've been saying, and what sparked
the original debate (argv[1]).


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk