On 2017-02-20 20:33 +0100, Marvin Gülker wrote: > the following program should switch to the current locale and then > print > the name of that locale: > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > #include <locale> > #include <iostream> > > int main() > { > std::locale::global(std::locale("")); > > std::locale current_locale; > std::cout << "Locale is now: " << current_locale.name() << > std::endl; > return 0; > } > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > It appears, however, that it doesn't do that on my 32-bits Windows 7. > The program compiles fine, but when I execute it, I get this (after > the usual "application has requested the runtime yadda yadda"): > > terminate called after throwing an instance of > 'std::runtime_error' > what(): locale::facet::_S_create_c_locale name not valid > > (That is, an std::runtime_error exception is thrown by the > constructor > of std::locale) > > I used the locale name "" (empty string), which should refer to the > environment's locale and should be available on any platform (I even > think it is required to do that, but I don't have a C++ standard at > hand). Using the "C" locale works, but any other value causes the > above problem. A comment in GCC source code (libstdc++-v3/config/locale/generic/c_locale.cc) said: Currently, the generic model only supports the "C" locale. See http://gcc.gnu.org/ml/libstdc++/2003-02/msg00345.html Read that thread and the follow-ups to get more information. -- Xi Ruoyao <ryxi@xxxxxxxxxxxxxxxxx> School of Aerospace Science and Technology, Xidian University