473,746 Members | 2,589 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem in using std::locale on unix system.

Hi,

I got trouble when I try to change the locale used in a program foo.cc
// ----------------- begin
#include <iostream>
#include <locale>
#include <exception>
using namespace std;

int main(int argc, char** argv)
{
try{
locale l(argv[1]);
cout.imbue(l);
cout << "Set locale to " << l.name() << " works" << endl;
}
catch (std::runtime_e rror& e)
{
cout << argv[1] << " : " << e.what() << endl;
}
}

// ----------------- end
g++ -o foo foo.cc

I try to set each locale on the locale unix machine :

for loc in `locale -a`; do ./foo $loc; done

Then some locale works, some not :
Set locale to C works
common : locale::facet:: _S_create_c_loc ale name not valid
en_US.UTF-8 : locale::facet:: _S_create_c_loc ale name not valid
Set locale to C works
iso_8859_1 : locale::facet:: _S_create_c_loc ale name not valid
iso_8859_15 : locale::facet:: _S_create_c_loc ale name not valid
en_CA : locale::facet:: _S_create_c_loc ale name not valid
en_CA.ISO8859-1 : locale::facet:: _S_create_c_loc ale name not valid
en_US : locale::facet:: _S_create_c_loc ale name not valid
en_US.ISO8859-1 : locale::facet:: _S_create_c_loc ale name not valid
en_US.ISO8859-15 : locale::facet:: _S_create_c_loc ale name not valid
en_US.ISO8859-15@euro : locale::facet:: _S_create_c_loc ale name not
valid
fr_CA : locale::facet:: _S_create_c_loc ale name not valid
fr_CA.ISO8859-1 : locale::facet:: _S_create_c_loc ale name not valid

If I change compiler from g++ to CC, more locale are allowed.

Set locale to C works
common : System does not recognize this locale name
Set locale to en_US.UTF-8 works
Set locale to C works
iso_8859_1 : System does not recognize this locale name
iso_8859_15 : System does not recognize this locale name
Set locale to en_CA works
Set locale to en_CA.ISO8859-1 works
Set locale to en_US works
Set locale to en_US.ISO8859-1 works
Set locale to en_US.ISO8859-15 works
Set locale to en_US.ISO8859-15@euro works
Set locale to fr_CA works
Set locale to fr_CA.ISO8859-1 works

.... Ok for iso_8859_15, the library
/usr/lib/locale/iso_8859_1/iso_8859_15.so. 2 does not exists,
but the lib /usr/lib/locale/iso_8859_1/iso_8859_1.so.2 exists.

Why is there differences between two compilers ?
Why a locale is not accepted, despite an existing library ?

thanks for your help.

Nov 28 '06 #1
2 11920

cris napsal:
Hi,

I got trouble when I try to change the locale used in a program foo.cc
// ----------------- begin
#include <iostream>
#include <locale>
#include <exception>
using namespace std;

int main(int argc, char** argv)
{
try{
locale l(argv[1]);
cout.imbue(l);
cout << "Set locale to " << l.name() << " works" << endl;
}
catch (std::runtime_e rror& e)
{
cout << argv[1] << " : " << e.what() << endl;
}
}

// ----------------- end
g++ -o foo foo.cc

I try to set each locale on the locale unix machine :

for loc in `locale -a`; do ./foo $loc; done

Then some locale works, some not :
Set locale to C works
common : locale::facet:: _S_create_c_loc ale name not valid
en_US.UTF-8 : locale::facet:: _S_create_c_loc ale name not valid
Set locale to C works
iso_8859_1 : locale::facet:: _S_create_c_loc ale name not valid
iso_8859_15 : locale::facet:: _S_create_c_loc ale name not valid
en_CA : locale::facet:: _S_create_c_loc ale name not valid
en_CA.ISO8859-1 : locale::facet:: _S_create_c_loc ale name not valid
en_US : locale::facet:: _S_create_c_loc ale name not valid
en_US.ISO8859-1 : locale::facet:: _S_create_c_loc ale name not valid
en_US.ISO8859-15 : locale::facet:: _S_create_c_loc ale name not valid
en_US.ISO8859-15@euro : locale::facet:: _S_create_c_loc ale name not
valid
fr_CA : locale::facet:: _S_create_c_loc ale name not valid
fr_CA.ISO8859-1 : locale::facet:: _S_create_c_loc ale name not valid

If I change compiler from g++ to CC, more locale are allowed.

Set locale to C works
common : System does not recognize this locale name
Set locale to en_US.UTF-8 works
Set locale to C works
iso_8859_1 : System does not recognize this locale name
iso_8859_15 : System does not recognize this locale name
Set locale to en_CA works
Set locale to en_CA.ISO8859-1 works
Set locale to en_US works
Set locale to en_US.ISO8859-1 works
Set locale to en_US.ISO8859-15 works
Set locale to en_US.ISO8859-15@euro works
Set locale to fr_CA works
Set locale to fr_CA.ISO8859-1 works

... Ok for iso_8859_15, the library
/usr/lib/locale/iso_8859_1/iso_8859_15.so. 2 does not exists,
but the lib /usr/lib/locale/iso_8859_1/iso_8859_1.so.2 exists.

Why is there differences between two compilers ?
Why a locale is not accepted, despite an existing library ?

thanks for your help.
Hi. I do not know, which compiler is under your CC. I have only one
idea. This compiler may have some own set of locales. Maybe is it
nonsense, I do not know.

I tried your code on SUSE Linux10.1/64-bit. (I have to add #include
<stdexcept>, but I do not think it has anything with your problem). I
got about 350 working locales and only one not working (some japanese -
I probably do not have installed all necessary stuff for it). I have no
other Unix here, sorry.

Nov 28 '06 #2
cris wrote:
Hi,

I got trouble when I try to change the locale used in a program foo.cc
You need to check documentation of your C library function setlocale.
std::locale will use the same names as setlocale.

On linux with glibc locale names are formed like this:

<language_short _name>_<country short name>[@charset]

en_US
en_GB
es_ES
es_AR

Nov 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
3447
by: jrefactors | last post by:
If the C programs have UNIX system calls such as fork(), alarm(), etc.., we should call it UNIX programs, not traditional C programs? We couldn't compile the programs with system calls using VC++ compiler. I need to compile it under UNIX platform. correct? any other alternatives?? Please advise. Thanks!!
0
1335
by: jalkadir | last post by:
When compiling this progra, I get an error that reads: *** Compiler : GNU GCC Compiler (called directly) -------------------------------------------------------------------------------- ..objs\exception.o(.bss+0x0):exception.cpp: multiple definition of `jme::native_loc' ..objs\main.o(.bss+0x0):main.cpp: first defined here collect2: ld returned 1 exit status Process terminated with status 1 (0 minutes, 4 seconds) ***
5
3545
by: markus | last post by:
Hi, I have a question that deals with the standard c library VS (Unix) system calls. The question is: which header files (and functions) are part of the C library and which header files (and function calls) are part of the (Unix) system calls. The cause of my confusion is that for example stdio.h is considered
4
2561
by: B.D. | last post by:
Can anyone explain way the transformation to upper case doesn't work correctly in the following code if PROBLEM is defined but works correctly if it's not defined? I'm using VC 7.1 #include <locale> #include <string> #include <algorithm>
10
10132
by: Jeffrey Walton | last post by:
Hi All, I've done a little homework (I've read responses to similar from P.J. Plauger and Dietmar Kuehl), and wanted to verify with the Group. Below is what I am performing (Stroustrup's Appendix D recommendation won't compile in Microsoft VC++ 6.0). My question is in reference to MultiByte Character Sets. Will this code perform as expected? I understand every problem has a simple and elegant solution that is wrong.
4
8281
by: mathieu | last post by:
Hi, I am having a hard time understanding how to use std::ws. I am trying to parse a simple string (*). My goal would be that 'st' contains 'Hello World'. I thought that using std::ws would indeed do what I was looking for. Thanks for suggestion, -Mathieu
2
3893
by: year1943 | last post by:
There was the same topic not so long ago, but as I see it stays w/o answer: http://groups.google.ru/group/comp.lang.c++/browse_thread/thread/9a05d7bba9394a60/fe109c899f916871?lnk=gst&q=locale+imbue&rnum=1&hl=ru#fe109c899f916871 As Bjarne Stroustrup said in his book, "in Stroustrup (retranslated from German) "Setting the global locale does not affect existing input/output streams. The streams continue to use those locales that were...
5
3595
by: Sashi Asokarajan | last post by:
Hello, recently I stepped over Strotrup's TC++PL (third ed.) Chapter D.1 where the localization support of the C++ stdlib is explained. http://www.research.att.com/~bs/3rd_loc.pdf ] Unfortunately the constructor fails if I try to instantiate std::locale for locales other than C or POSIX. With (only) LANG="de.DE.UTF-8" set in ENV the following code thows an exception: std::locale loc("");
4
3375
by: dertopper | last post by:
Hello newsgroup, is it possible to create a std::locale object without changing the global C locale? Is this implementation defined? My problem is that I work in a multi-threaded environment that has to deal with two different locales. Unfortunately, the code uses plain C functions for IO at many places. However, there is a single point that uses std::isprint with a C++ locale that is different from the standard locale. That's why I'm...
0
8800
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9350
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6772
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4586
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4836
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3292
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2199
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.