Warm tip: This article is reproduced from serverfault.com, please click

Inserting a "£" sign in an output string in C++

发布于 2010-09-30 14:02:22

I have the following code:

cout << "String that includes a £ sign";

However, the £ sign is not being recognised by the compiler, and instead an accented u is being displayed. I'm able to insert one using the following method:

cout << "String that includes a " << char(156) << " sign";

where 156 is the ASCII code of the £ sign. Is there a way I can include this ASCII code in the string itself without having to separate it out like this? For example:

cout << "String that includes a <some way of iserting the £ sign> sign";
Questioner
user360907
Viewed
11
Paul R 2010-09-30 22:05:09

£ does not have an "ASCII code" - ASCII is 7 bits (0..127). There are various extended 8 bit characters sets which include £ but there is no single standard for this and the £ symbol may have various different values in different environments. You should probably be using Unicode if you need international symbols with maximum portability.