说,我可以使用_create_locale在我的C程序中设置语言环境:

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

但是我需要的是相反的方式,即检索调用线程的语言环境名称(上面函数的第二个参数)。知道怎么做吗?

PS。我知道现代Windows使用LCID。我需要此语言环境名称以与旧代码兼容。

最佳答案

希望您可以使用Standard 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 *

关于c++ - 如何获取我的线程的语言环境名称?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16431220/

10-11 23:06
查看更多