std::locale throws runtime_error exception to “en_US.UTF-8” locale

只愿长相守 提交于 2019-12-11 17:45:59

问题


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.

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.

I am compiling in with configuration: Debug Win32

Thanks in advance.


回答1:


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

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.



来源:https://stackoverflow.com/questions/58013410/stdlocale-throws-runtime-error-exception-to-en-us-utf-8-locale

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!