在OS X上设置区域设置崩溃 [英] Setting locales on OS X crashes

查看:170
本文介绍了在OS X上设置区域设置崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码在Linux上正常工作,但在OS X 10.7上引发异常:

The following code works fine on Linux but throws an exception on OS X 10.7:

#include <iostream>
#include <locale>
#include <stdexcept>

int main() try {
    std::locale::global(std::locale(""));
    std::cout << "Using locale: " << std::locale().name() << "\n";
}
catch (std::runtime_error const& e) {
    std::cout << e.what() << "\n";
    return 1;
}

OS X上的输出是:

The output on OS X is:


locale :: facet :: _ S_create_c_locale 名称无效

但是,标准明确说明


有效的字符串参数值集合C和任何实现定义的值。

The set of valid string argument values is "C", "", and any implementation-defined values.

所以无论什么原因上面的行为违反了标准。

So whatever causes the behaviour above is violating the standard.

编译器使用的是clang ++ 3.1(tags / Apple / clang-318.0。 58);我也尝试过通过Homebrew安装的GCC 4.7,结果相同。

The compiler used is clang++ 3.1 (tags/Apple/clang-318.0.58); I’ve also tried it with GCC 4.7, installed via Homebrew, with the same result.

其他人可以验证这个问题吗?是什么原因?我做错了什么?这是OS X中的错误吗?

(也许是涉及另一个 xlocale 问题,但错误实际上完全不同。)

(Maybe this relates to another xlocale problem but the errors are actually completely different.)

推荐答案

我不认为你使用xlocale。我相信你的问题是与libstdc ++,它使用不同的区域设置支持库,不支持在OS X上,作为问题EitanT链接到状态。

I don't think you're using xlocale. I believe that your problem is with libstdc++, which uses a different locale support library that is not supported on OS X, as the question EitanT links to states.

如果你切换到libc ++你的程序将工作。

If you switch to libc++ your program will work.

这篇关于在OS X上设置区域设置崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆