Search code examples
c++ascii

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


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";

Solution

  • £ 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.