std :: locale将runtime_error异常抛出给"en_US.UTF-8";地区 [英] std::locale throws runtime_error exception to "en_US.UTF-8" locale

查看:268
本文介绍了std :: locale将runtime_error异常抛出给"en_US.UTF-8";地区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的std :: locale项目中的以下代码段存在一个奇怪的问题:

So I have a strange issue with the following code snippet in my project with std::locale:

std::locale local;     
try {
    local = std::locale ("en_US.UTF-8");
}
catch (std::runtime_error &e) {
    std::cout  << e.what();
}

它在生产代码中引发异常消息:错误的语言环境名称",但是如果我在空的沙箱项目中运行它,则会正确设置本地语言.

It throws an exception with a message: "bad locale name" in my production code, but in case I run it in an empty sandbox project it set the local correctly.

我想我的项目在我不熟悉的地方有一个配置,但是我不知道应该在哪里看或可以在哪里设置.在我的项目中,我在main()函数的开头尝试过此操作,以消除它在代码中其他位置设置的可能性,这就是为什么我猜测它在配置文件中的某个位置设置的原因.

I suppose my project has a config somewhere that I am not familiar with, but I do not have any clue where should I look or where can it be set. In my project I tried it in the beginning of the main() function to eliminate the possibility that it is set somewhere else in the code, this why I am guessing it is set somewhere in a config file.

我正在使用以下配置进行编译:调试Win32

I am compiling in with configuration: Debug Win32

谢谢.

推荐答案

Windows上的语言环境名称与现代POSIX-ish系统上的语言环境名称不同.特别是,它们永远不会包含"UTF-8"或任何类似内容.

Locale names on Windows are different from those on modern POSIX-ish systems. In particular, they never include "UTF-8" or anything similar.

在Windows中,不支持通过选择标准语言环境来打开UTF-8.使用 Boost可能会或可能不会带来更好的运气.locale .

There is no support for UTF-8 in Windows that can be turned on by selecting a standard locale. You may or may not have better luck with Boost.Locale.

这篇关于std :: locale将runtime_error异常抛出给"en_US.UTF-8";地区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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