Thomas Sampson

C++ Pound Sign

28 Comments

Last night I got so fustrated trying to do something really simple in c++. I needed to represent a GBP £ sign in a c++ windows console application. My smug friend using linux terminal and GCC assured me that the pound sign did not keep him up last night, but for me compiling away on MSBUILD it was a nightmare. Something so simple. yet after trying EVERY POSSIBLE mixture of search terms, google provided me with nothing! For once google had failed me! It did however suggest escape character methods and all sorts of other fruitfull options but none that worked. When outputing a £ to the command line I got “u”. Not much use when your trying to represent a price in GBP! It turns out that microsoft, being american, does not naturally support the character and the following is required to achieve such a simple thing.

//show pound sign in c++

char pound=156;

cout << “This will cost ” <<pound << “5.00” ;

Why am I blogging this?? In the hope that after this blog post gets indexed by google, the many others who appear on forums searching for this solution, and those who will come across it in the future, will find this and get an early night! Unlike myself 😛

Author: tomtech999

I have recently graduated with a 1st class degree in MComp Games Software Development at Sheffield Hallam University, focusing primarily on application development in C++, with experience in graphics programming, scripting languages, DVCS/VCS and web technology. In my spare time I enjoy Drumming, Reading and Snowboarding!

28 thoughts on “C++ Pound Sign

  1. Omg, I love you so much. I went to the extent of scouring through the character map to see if I was being retarded. Out of interest how did you work it out in the end?

  2. Oh and is this ANSI C compliant?

  3. Honestly I just thought of all the ways I could possibly put this damn pound sign into my app! Then I remebered back to a lecture where I first saw odd data type assignments like char foo=23, then realised I needed the right character code for a pound sign, and yes I assume this is ANSI compliant. I got to my tutorial the following morning and realised my tutor had emailed this solution to the rest of the class, if only I had checked my email! 😀

  4. You sir, are a true master among men, i’ve been looking for this solution for hours now and if it was not for your blog, Google would have failed me too.

    Thank you so much 🙂

  5. omg thank you so much will help with my school work so much.

    doing wage slip’s without a pound sign. she would rip my head off thanks

  6. Well, i wanted this for a quick program and found it after one search on Google, thankyou 😀

  7. Thank you so so much! Google almost failed me and my mind couldn’t cope with that :p.

  8. Thanks so much! I’ve just spent the past hour trying to figure this one out! Got straight to this once I realised it was a cout problem (I’ve been working with char to string conversion, though it was that). Thanks again!

  9. You are an absolute number one, I’ve never been able to figure this out and had to change a program I wrote to use dollar signs. Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you!!!!!!!!!!

  10. Hi, I have a question. Why have you initialised pound to 156?

  11. Oh right I got it. ASCII code for £ is 156. Get rid of my comment above

  12. You can find this information by Googling for ‘ascii table’. If you don’t find the correct code there, try adding ‘extended’. This should also be available in the character map on Windows, just look for the ASCII value. If you’re still at a loss, look into Unicode and Unicode string literals.

  13. Again, one of the many google devotees who would have failed without this simple 2 lines of code. Thank you very much, and btw your blog i now the first result when searching for pound sign C++.

  14. Dont know why c++ is set up to change charicters. But it has been defined in such a way that you can define any charicter code within a string, without resorting to seperate variables.

    The hex value for 156 is 9c. To supply the hex code for a charicter in a string use \x.

    So for a string such as “This will cost £5.00″ use:
    “This will cost \x9c5.00”

    It doesnt look as pretty, but its potentially more efficient.

    Regards

  15. Pingback: C++ £ @ Andy Longhurst

  16. Sorted me out! Thanks Tom!

  17. You can look up other such symbols in an ASCII character chart and output them. For example a yen symbol is 157. Those are the only two “foreign” (i.e. non-dollar) currency symbols in the extended ASCII codes. Good luck finding a euro symbol without supporting Unicode or changing the font.

  18. Thank you very much =) Trying to do some extra work for my object orientated programming lectures and couldnt for the live of me remember such a simple solution. You made google usefull again

  19. truly amazing

  20. Fantastic solution except for one thing.

    It didn’t work for me, a quick google around and i found that where some people use 156, others seem to use 163.

    163 works for me, but other people in my class use 156.

    What’s the difference? I’m on a mac and they’re on PCs. Who’s being the inconsistent one here? Microsoft or Apple (i have no bias, i’m just curious).

    Otherwise, thanks for such a great solution.

  21. Thank you sir!

  22. I won’t say this to many men, but i love you! I am so glad you put this on ur blog and google’s picked it up, i’ve been looking for this for ages! 😀

  23. It’s really weird that on the ASCII table it says 163 for the pound sign, but the character code 156 works for me. thanks a lot! neat solution and saved me a lot of trouble

  24. I am on a Forensic Computing undergrad course, and although the lecturer has told us not to worry about the £ sign, being British and all, I thought I had better find out how to print it.

    First Google, came up with your post and I would like to thank you for posting it, for ALL of us!

  25. Congratulations, you were first on google! Ha

  26. Thanks for the post, I found my answer within seconds 🙂

  27. Yeah…You saved me. You’re great.

  28. 8 Years on from the original post and this helped me loads!
    Couldn’t find this info anywhere else. Thanks!

Leave a reply to tomtech999 Cancel reply