Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::locale::facet::_S_create_c_locale name not valid

Tags:

c++

c++11

I'm trying to learn different locales and handling unicode and I chose to make all my strings UTF-8 and I decided to run the following code but for some reason it throws an error and I cannot figure out why.. I tried every locale so far and none except "C" works.. I tried the list of locales found here: http://gcc.gnu.org/onlinedocs/libstdc++/manual/localization.html

and their example:

#include <iostream>
#include <string>

int main()
{
    std::locale::global(std::locale("en_US.UTF-8"));

    return 0;
}

Results in:

terminate called after throwing an instance of 'std::runtime_error'
what(): locale::facet::_S_create_c_locale name not valid

What am I doing wrong?

I'm using Mingw-Builds gcc/g++ 4.8.1 with the latest codeblocks on Windows 8. Language is set to EN_US and sometimes I switch to EN_GB.

like image 802
Brandon Avatar asked Sep 08 '13 17:09

Brandon


Video Answer


1 Answers

I ran into same problem last week, I wrote a program to print all supported locale names under Windows OS.

See my answer Print all std::locale names (Windows)

Locale that you are looking for is just "en-US" under Windows.

like image 106
user1 Avatar answered Oct 07 '22 20:10

user1