2013-05-08 109 views
1

说,我可以用_create_locale这样从我的C程序中设置的语言环境:如何获取我的线程的语言环境名称?

localeUS = _create_locale(LC_ALL, "English_United States.1252"); 

但我需要的是相反的,即检索区域名称(函数的第二个参数上面)调用线。任何想法如何做到这一点?

PS。我知道现代Windows使用LCID。为了与旧代码兼容,我需要此区域名称。

回答

3

希望你可以使用标准C++。

std::locale::name

#include <locale> 
#include <iostream> 
#include <string> 

int main() 
{ 
    std::locale loc(std::locale(), new std::ctype<char>); 
    std::cout << "The default locale is " << std::locale().name() << '\n' 
       << "The user's locale is " << std::locale("").name() << '\n' 
       << "A nameless locale is " << loc.name() << '\n'; 
} 

输出:

The default locale is C 
The user's locale is en_US.UTF8 
A nameless locale is * 
+1

感谢。刚刚通过逆向工程发现你的示例,简单地做'strCurrentLocale = setlocale(LC_ALL,“”);'会做我需要的。 – c00000fd 2013-05-08 02:13:22

+0

根据链接文档,'std :: locale()'*“构造**全局** C++语言环境”*“的副本。没有记录'std :: locale(“”)'的行为。由于Windows控制每个线程的语言环境,因此检索当前线程的语言环境的方法是什么? – IInspectable 2017-08-01 01:57:04

相关问题