有效的区域设置名称

发布于 2024-08-14 16:49:18 字数 540 浏览 2 评论 0原文

如何找到有效的区域设置名称?

我目前使用的是 MAC OS X。
但有关其他平台的信息也很有用。

#include <fstream>
#include <iostream>


int main(int argc,char* argv[])
{
    try
    {
        std::wifstream  data;
        data.imbue(std::locale("en_US.UTF-16"));
        data.open("Plop");
    }
    catch(std::exception const& e)
    {
        std::cout << "Exception: " << e.what() << "\n";
        throw;
    }
}

% g++ main.cpp
% ./a.out
Exception: locale::facet::_S_create_c_locale name not valid
Abort

How do you find valid locale names?

I am currently using MAC OS X.
But information about other platforms would also be useful.

#include <fstream>
#include <iostream>


int main(int argc,char* argv[])
{
    try
    {
        std::wifstream  data;
        data.imbue(std::locale("en_US.UTF-16"));
        data.open("Plop");
    }
    catch(std::exception const& e)
    {
        std::cout << "Exception: " << e.what() << "\n";
        throw;
    }
}

% g++ main.cpp
% ./a.out
Exception: locale::facet::_S_create_c_locale name not valid
Abort

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

画骨成沙 2024-08-21 16:49:18

此页面显示:

构造函数调用 std::locale("") 创建一个代表用户偏好的 locale 对象。标准没有说明这意味着什么,但在许多系统上,库会替换环境变量中找到的任何内容(通常是 LANGLC_ALL)来代替空字符串。例如,美国语言环境的通用名称是“en_US”。 (在 POSIX 系统上,您可以键入 locale -a 来列出支持的区域设置的名称。)

locale -a 应该适合您。

如果您的意思是从 C++ std 库以编程方式,我不确定。

这个堆栈溢出问题可能也相关但他似乎并没有太多的反应。

编辑

要使用UTF-16,您可能需要使用libiconv这个问题

This page says:

The constructor call std::locale("") creates a locale object that represents the user's preferences. The standard doesn't say what this means, but on many systems the library substitutes whatever is found in an environment variable (often LANG or LC_ALL) in place of the empty string. A common name for the American locale, for example, is "en_US". (On POSIX systems you can type locale -a to list the names of supported locales.)

locale -a should work for you.

If you mean programatically from the C++ std libary I'm not sure.

This stack overflow question is probably also relevant, but he doesn't seem to have had much response.

Edit

To use UTF-16 you probably will need to use libiconv as mentioned in this question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文