473,757 Members | 10,263 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 11921

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
3451
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
1336
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
3546
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
2562
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
10135
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
8282
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
3896
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
3596
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
9489
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9298
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
8737
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7286
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
6562
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5172
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...
1
3829
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
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2698
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.