string and pound symbol

Q

quat

Hi,

I have a char* string where I assigned a string literal with the British
pound symbol, which is included in the extended ASCII, at least on my OS.
However, when I cout the string, I get a modified u in place of the pound
symbol. Why is that? If I output the ASCII code of the pound symbol it
outputs just fine--but not when in a char*.
 
A

Alf P. Steinbach

* quat:
I have a char* string where I assigned a string literal with the British
pound symbol, which is included in the extended ASCII, at least on my OS.

Well, there are numerous _different_ extensions of ASCII; nearly all
character sets in common use are extensions of ASCII.

However, when I cout the string, I get a modified u in place of the pound
symbol. Why is that?

Sounds platform-specific; just on the off-chance that it's relevant, see
If I output the ASCII code of the pound symbol it
outputs just fine--but not when in a char*.

Hum, well, _now_ it sounds more like a coding problem. But you don't
show any code. Sorry, no code, no help (no arms, no cake!).

Cheers,

- Alf
 
T

Tom

Hi,

I have a char* string where I assigned a string literal with the British
pound symbol, which is included in the extended ASCII, at least on my OS.
However, when I cout the string, I get a modified u in place of the pound
symbol. Why is that? If I output the ASCII code of the pound symbol it
outputs just fine--but not when in a char*.

Interesting challenge.

I suggest a help search on the following:

1) extended ascii
2) cin
3) LC_CTYPE
4) setlocale
5) code pages

The information about "setlocale" is where I believe you will be lead
to the solution.

I am interested in hearing if you have success with setlocale. I have
never had the need for it before; thus, I am very curious.

Your country code appears to be "gbr". The following listing was found
in help:

-------------------

The following is a list of country/regions strings recognized by
setlocale. Strings for countries/regions that are not supported by the
operating system are not accepted by setlocale. Three-letter
country/region-name codes are from ISO/IEC (International Organization
for Standardization, International Electrotechnical Commission)
specification 3166.

Country/Region Country/Region String
Australia "aus" or "australia"
Austria "austria" or "aut"
Belgium "bel" or "belgium"
Brazil "bra" or "brazil"
Canada "can" or "canada"
Czech Republic "cze" or "czech"
Denmark "denmark" or "dnk"
Finland "fin" or "finland"
France "fra" or "france"
Germany "deu" or "germany"
Greece "grc" or "greece"
Hong Kong "hkg", "hong kong", or "hong-kong"
Hungary "hun" or "hungary"
Iceland "iceland" or "isl"
Ireland "ireland" or "irl"
Italy "ita" or "italy"
Japan "japan" or "jpn"
Mexico "mex" or "mexico"
Netherlands "nld", "holland", or "netherlands"
New Zealand "new zealand", "new-zealand", "nz", or "nzl"
Norway "nor" or "norway"
People’s Republic of China "china", "chn", "pr china", or "pr-china"
Poland "pol" or "poland"
Portugal "prt" or "portugal"
Russia "rus" or "russia"
Singapore "sgp" or "singapore"
Slovak Repubic "svk" or "slovak"
South Korea "kor", "korea", "south korea", or "south-korea"
Spain "esp" or "spain"
Sweden "swe" or "sweden"
Switzerland "che" or "switzerland"
Taiwan "taiwan" or "twn"
Turkey "tur" or "turkey"
United Kingdom "britain", "england", "gbr", "great britain", "uk",
"united kingdom", or "united-kingdom"
United States of America "america", "united states", "united-states",
"us", or "usa"
 
T

TB

quat sade:
Hi,

I have a char* string where I assigned a string literal with the British
pound symbol, which is included in the extended ASCII, at least on my OS.
However, when I cout the string, I get a modified u in place of the pound
symbol. Why is that? If I output the ASCII code of the pound symbol it
outputs just fine--but not when in a char*.

I guess you're on Windows. Understand that a lot of things happen
between your call to std::cout and the displayed character.

You need to make up your mind about which "extended ascii" - charset
you intend on using.

Latin-1 is a subset of Unicode, and Ascii is a subset of Latin-1.
If you use Latin-1 and your host environment supports either that or
Unicode, then you should be able to get the correct character on the
display, otherwise some translation tables might be necessary,
depending on platform specific issues.

Here's a solution we used several years ago to make it work. It's not
in any way a perfect solution, and might be flawed, but testing it
just now, it still works on Windows XP.

http://www.cypher.nu/conasc.h

#include "conasc.h"
#include <ostream>
int main() {
conasc::enter();
std::cout<<'£';
conasc::leave();
return 0;
}

Prints '£' on the console instead of 'ù' as it would normally.
IIRC, it uses a translation table based on trail-and-error, and
switches the stream buffer used by std::cout with its own.
Most likely not thread-safe. But perhaps interesting. It's probably
better to construct a new stream with this translating buffer instead
of using conasc::enter() and conasc::leave().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top