c++ - 如何获取我的线程的区域设置名称?

标签 c++ c windows winapi crt

比如说,我可以使用 _create_locale 从我的 C 程序设置区域设置像这样:

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

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

PS。我知道现代 Windows 使用 LCID。我需要此区域设置名称以与旧代码兼容。

最佳答案

希望您能够使用标准 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/

相关文章:

C++函数cout重定向到文件

c++ - 嵌套类可以有指向外部类的成员指针吗?

c++ - 在 CLinkCtrl 上按下空格键后调用 TrackPopupMenu() 会导致发出警告消息蜂鸣声。为什么?

c - 如何在for循环中获取3次数组?

c - c 中导入的头文件使用了哪些函数?

c - C 套接字上的线程同步

c++ - 如何以编程方式设置系统IP

python - Windows 10在启动时运行python程序

c++ - 删除二叉搜索树中的节点时出错

c++ - 在 Visual Studio 2017 中禁用烦人的调试器通知