有效的区域设置名称
如何找到有效的区域设置名称?
我目前使用的是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此页面显示:
构造函数调用 std::locale("") 创建一个代表用户偏好的 locale 对象。标准没有说明这意味着什么,但在许多系统上,库会替换环境变量中找到的任何内容(通常是
LANG
或LC_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
orLC_ALL
) in place of the empty string. A common name for the American locale, for example, is "en_US". (On POSIX systems you can typelocale -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.