🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #7977

Re: Obtaining the Currency Symbol

#7977
From: Thomas Maeder [TeamB]
Date: Fri, 10 Dec 2004 22:14
98 lines
3482 bytes
"Roger Warren" <> writes:

> How can I obtain the currency symbol for the currenct locale/regional
> setting? I have tried using:
>
> ...
> struct lconv ll;
> struct lconv *conv = &ll;
> conv = localeconv();
> printf("Currency symbol: %s\n", conv->currency_symbol);
> ...
>
> But it doesn't seem to produce anything.

Questions about localization issues are always interesting, and I am
always surprised at what I see while experimenting ...

I hacked together the following:

#include <locale>
#include <iostream>
#include <ostream>

void dump_currency_symbol(char const *locname)
{
  try
  {
    typedef std::moneypunct<char> moneyp_type;
    std::cout << std::use_facet<moneyp_type>(std::locale(locname))
      .curr_symbol() << '\n';
  }
  catch (std::exception const &e)
  {
    std::cerr << e.what() << '\n';
  }
}

int main()
{
  dump_currency_symbol("");
  dump_currency_symbol("de_DE");
  dump_currency_symbol("de_CH");
  dump_currency_symbol("en_US.iso8859-1");
  dump_currency_symbol("de_CH.iso8859-1");
}


On my Linux box, the LANG environment variable defaults to en_US (that
was actually the first surprise ... I must have set it like that
because some porgram that I probably haven't been using for month
required it). If I run the program, as compiled by the latest gcc
(3.4.3), I get

$
EUR
Fr.
locale::facet::_S_create_c_locale name not valid
locale::facet::_S_create_c_locale name not valid


When I change LANG to de_CH, I get

Fr.
EUR
Fr.
locale::facet::_S_create_c_locale name not valid
locale::facet::_S_create_c_locale name not valid

, i.e. I can use std::locale("") to get a locale object the reflects
the current setting of the LANG environment variable.


The exceptions on the last two attempts are no surprise, though. The
names used here are my guesses at what locales are called on Windows;
don't bet your form on them. If anybody can tell me what the
equivalent of the Linux command

locale -a

(i.e. list all available locale names) is on Windows, I'd be very glad.


The real surprise came when I through C++BuilderX at the program to
run it on Windows. Whatever tampering I do with LANG and LC_MONETARY,
I always get

SFr.
SFr.
SFr.
SFr.
SFr.

which is good news for you, because German/Switzerland is my Windows
setting.


And when I use gcc (3.1.1) on Windows. Again, no matter what I set
LANG and LC_MONETARY to, I always get five empty lines ...
Technical Details
Message-ID: <m2hdmtu7gh.fsf@madbox2.local>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!newsfeed.icl.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <41b9992f$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,5c552075733153e4
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Obtaining the Currency Symbol
References: <41b9992f$1@newsgroups.borland.com>
From: maeder@glue.ch (Thomas Maeder [TeamB])
Organization: TeamB
Date: Fri, 10 Dec 2004 23:14:22 +0100
Message-ID: <m2hdmtu7gh.fsf@madbox2.local>
User-Agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Security Through
 Obscurity, linux)
Cancel-Lock: sha1:EFLOhWc0bwpvWDtZPWy5B9Szjz4=
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
NNTP-Posting-Host: 80.218.114.55
X-Trace: newsgroups.borland.com 1102716861 80.218.114.55 (10 Dec 2004 14:14:21 -0800)
Lines: 98
X-Authenticated-User: tmaeder
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!newsfeed.icl.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail