Cannot make locale work

Hi
I try to use locale in my Xcode project and receive the message

"terminate called after throwing an instance of 'std::runtime_error'
what(): locale::facet::_S_create_c_locale name not valid
Program received signal: “SIGABRT”.

Here is the code:

#include <iostream>
#include <locale>
using namespace std;
int main(int argc, const char** argv)
{

locale mylocale("en_US");
//locale mylocale("en_GB");
//locale mylocale("English");

return 0;
}

Can someone tell me what is wrong here?

My details:
Mac OSX 10.6
IDE - Xcode 3.2

Thanks a lot!
wr3
I am not an expert, but locales is in this format
 
locale "lang[_country_region[.code_page]]" 


So you could try:
 
"English_en_US"


This brackets '[]' denotates optional param.

edit:
I think that empty string means system locale:
 
locale loc("")

note that it is not the same as:
 
locale loc;

witch refers to different locale.

edit2: I might be wrong, this PDF states that is implementation specific:
http://www.angelikalanger.com/Conferences/Slides/CppLocales-ACCU-2001.pdf
Last edited on
Thanks, morando for your reply.
I tried "English_en_US" - still no progress.

wr3
> Can someone tell me what is wrong here?

GCC does not have support for any locale other than the C and POSIX locales for platforms other than Linux.

You could try using clang instead (which hopefully isn't crippled by linuxism).

I use Boost.Locale with an ICU backend on all platforms.
http://www.boost.org/doc/libs/1_49_0/libs/locale/doc/html/index.html
http://site.icu-project.org/
Hey JLBorges, I will certainly try Boost.Locale if this is a way out.
BTW, icu is another problem for me - it does not work.
I have icu4c 4_8_1_1 in /usr/local,
boost_1_49_0 libraries, in /usr/local/boost.
I built boost :: regex successfully with bjam saying "-has_icu builds: yes", but then if I add #include"boost/regex/icu.hpp" to file main.cpp and compile,I receive 451 errors beginning with:
/usr/local/boost_1_49_0/boost/regex/icu.hpp:22:28: error: unicode/utypes.h: No such file or directory
/usr/local/boost_1_49_0/boost/regex/icu.hpp:23:27: error: unicode/uchar.h: No such file or directory
etc. etc.
Worse even,if I just put ANY Unicode header file to my main.cpp I got the same error message - "no such file".
So boost :: regex does not see icu and icu all alone would not work either.

Did you have to add search path for icu to your compiler?
Thanks for your help.
p.s. unfortunately clang does not help.
Last edited on
> Did you have to add search path for icu to your compiler?

Yes, certainly. And also link with the icu library.

That is the reason for the compiler errors "no such file".
You need to add -I <icu include directory> to the command line
>You need to add -I <icu include directory> to the command line

Got it and put to use. My first experience fine-tuning gcc! In terminal the following works without errors :
"Valery-Osavlyuks-iMac:CHECKUNICODE spaset$ g++ -I/usr/local/include/unicode -L/usr/local main.cpp -o main".

But how to make it part of my Xcode project?
I cannot use it as script because Run Script is a build phase whereas my problem relates to compiling. Just to be sure I tried it - no change.
Also set Header Search Paths and Library Search Paths in Project Build settings -nothing happens.

>Yes, certainly. And also link with the icu library.

Are you talking about Linking in Project/Target Build settings? Other Linker Flags, by any chance?




> But how to make it part of my Xcode project?

Don't really know - never used Xcode much. But I would be surprised if setting 'Header Search Paths' and 'Library Search Paths' doesn't work.

Topic archived. No new replies allowed.