|
Boost : |
Subject: Re: [boost] [nowide] request for clarification
From: Peter Dimov (lists_at_[hidden])
Date: 2017-06-16 22:06:55
Niall Douglas wrote:
> > That main(argc,argv) receives parameters converted from native UTF-8
> > internal API to current locale's codepage - generally not being able to
> > represent the all the required charset (since Windows does not support
> > UTF-8 as native locale)
>
> This is incorrect. You have been able to set the Windows console to UTF-8
> for many years. Just issue `chcp 65001`, your console is now in UTF-8 and
> UTF-8 strings will present to argv.
You can set the console to UTF-8 and it will display UTF-8 correctly, but
will UTF-8 strings come in (the narrow) argv? I think not.
#include <iostream>
int main( int argc, char const* argv[] )
{
std::cout << argv[1] << std::endl;
}
C:\Users\Peter Dimov>chcp 65001
Active code page: 65001
C:\Projects\testbed2017>debug\testbed2017.exe пÑоба
?????
Whereas:
#include <boost/nowide/args.hpp>
#include <iostream>
int main( int argc, char const* argv[] )
{
boost::nowide::args args( argc, argv );
std::cout << argv[1] << std::endl;
}
Oops, a compile error, Nowide doesn't take char const*. All right,
#include <boost/nowide/args.hpp>
#include <iostream>
int main( int argc, char * argv[] )
{
boost::nowide::args args( argc, argv );
std::cout << argv[1] << std::endl;
}
And now:
C:\Projects\testbed2017>debug\testbed2017.exe пÑоба
����������
See? Much better. :-) Although there's still room for improvement:
#include <boost/nowide/args.hpp>
#include <boost/nowide/iostream.hpp>
int main( int argc, char* argv[] )
{
boost::nowide::args args( argc, argv );
boost::nowide::cout << argv[1] << std::endl;
}
C:\Projects\testbed2017>debug\testbed2017.exe пÑоба
пÑоба
Or alternatively,
#include <boost/nowide/args.hpp>
#include <cstdio>
int main( int argc, char* argv[] )
{
boost::nowide::args args( argc, argv );
std::puts( argv[1] );
}
with the same result.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk