问题
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