std::locale::global(std::locale("zh-CN")) Gets "Bad locale name"??

std::locale::global(std::locale("zh-CN")) Gets "Bad locale name"??

Post by Fred » Wed, 15 Apr 2009 16:44:19


Hi everyone:

I'm playing with C/C++ locale recently.
I've got a program which uses Chinese character as file name or
in the path of a file. When using fstream to manipulate files, I
choose to use MBCS instead of Unicode, so I have to specify the
locale.
At first I tried setlocale(LC_CTYPE, "chinese") and it works
well, however, it's a C-style locale setting, for C++,
std::locale::global() is preferable. Unfortunately, I just can't set
the correct locale by calling std::locale::global(). I have tried:
std::locale::global(std::locale("zh-CN")); but I get a "Bad locale
name" exception, it's strange, because "zh-CN" conforms to the
specification defined in MSDN( http://www.yqcomputer.com/
dd373814(VS.85).aspx). Later I found std::locale::global(std::locale
("Chinese")); works well, then I'm totally confused. Could anybody
figure it out?