473,396 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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_error& 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_locale name not valid
en_US.UTF-8 : locale::facet::_S_create_c_locale name not valid
Set locale to C works
iso_8859_1 : locale::facet::_S_create_c_locale name not valid
iso_8859_15 : locale::facet::_S_create_c_locale name not valid
en_CA : locale::facet::_S_create_c_locale name not valid
en_CA.ISO8859-1 : locale::facet::_S_create_c_locale name not valid
en_US : locale::facet::_S_create_c_locale name not valid
en_US.ISO8859-1 : locale::facet::_S_create_c_locale name not valid
en_US.ISO8859-15 : locale::facet::_S_create_c_locale name not valid
en_US.ISO8859-15@euro : locale::facet::_S_create_c_locale name not
valid
fr_CA : locale::facet::_S_create_c_locale name not valid
fr_CA.ISO8859-1 : locale::facet::_S_create_c_locale 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 11890

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_error& 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_locale name not valid
en_US.UTF-8 : locale::facet::_S_create_c_locale name not valid
Set locale to C works
iso_8859_1 : locale::facet::_S_create_c_locale name not valid
iso_8859_15 : locale::facet::_S_create_c_locale name not valid
en_CA : locale::facet::_S_create_c_locale name not valid
en_CA.ISO8859-1 : locale::facet::_S_create_c_locale name not valid
en_US : locale::facet::_S_create_c_locale name not valid
en_US.ISO8859-1 : locale::facet::_S_create_c_locale name not valid
en_US.ISO8859-15 : locale::facet::_S_create_c_locale name not valid
en_US.ISO8859-15@euro : locale::facet::_S_create_c_locale name not
valid
fr_CA : locale::facet::_S_create_c_locale name not valid
fr_CA.ISO8859-1 : locale::facet::_S_create_c_locale 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
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++...
0
by: jalkadir | last post by:
When compiling this progra, I get an error that reads: *** Compiler : GNU GCC Compiler (called directly) --------------------------------------------------------------------------------...
5
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...
4
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...
10
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...
4
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...
2
by: year1943 | last post by:
There was the same topic not so long ago, but as I see it stays w/o answer:...
5
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 ] ...
4
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.