gpt4 book ai didi

c++ - 在 OS X 上设置语言环境崩溃

转载 作者:可可西里 更新时间:2023-11-01 17:58:50 25 4
gpt4 key购买 nike

以下代码在 Linux 上运行良好,但在 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 上的输出是:

locale::facet::_S_create_c_locale name not valid

但是,标准明确指出

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

所以不管是什么原因导致上述行为都违反了标准。

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

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

(可能是这个 relates to another xlocale problem 但错误实际上是完全不同的。)

最佳答案

我认为您没有使用 xlocale。我认为您的问题出在 libstdc++ 上,它使用 OS X 不支持的不同语言环境支持库,因为问题 EitanT 链接到状态。

如果您切换到 libc++,您的程序将运行。

关于c++ - 在 OS X 上设置语言环境崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11190072/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com