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
#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
#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
#include
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
#include <cstdio>
int main( int argc, char* argv[] )
{
boost::nowide::args args( argc, argv );
std::puts( argv[1] );
}
with the same result.