Displaying hearts, clubs, spades, diamonds

Started by
4 comments, last by vinb 18 years, 8 months ago
I'm building a console version of blackjack and I would like to display the suite as a symbol rather than a letter. I did some research and found that \u2660 is supposed to display the hearts symbol. But when I compile the code, I get a warning "unrecognized character escape sequence". I'm using C++. Any help would be greatly appreciated. Thanks.
Advertisement
ASCII code 3 is heart, 4 is diamond, 5 is clubs and 6 is spades.

To output them just use something like:

cout << char(4); //outputs diamond

or for strings:

cout << "\4"; //same
The DOS console happens to map those characters to those symbols as well, but they're really not supposed to be printable characters.

As for \u2660, first of all, sequences starting with \u are Java-speak for Unicode characters (for C++ you'll need to specify the data in some other way, probably manually, byte-by-byte - which depends on which Unicode encoding you will be using), and there's extra work that has to be done to use Unicode anyway. Plus, the console won't display it anyway.

Trust me, it's not worth the effort. You will learn far, far more by getting the rest of your program to work, than trying to polish off one graphical detail. Later in your career you can look into doing things with various graphics APIs, which is about that point at which you can also sanely start to think about Unicode and other sorts of i18n issues.
Quote:Original post by vinb
I did some research and found that \u2660 is supposed to display the hearts symbol. But when I compile the code, I get a warning "unrecognized character escape sequence".

"\u" is not a valid escape sequence in C++, just like the error says. Where ever you got that code was not talking about C++. I'm guessing that it is Unicode and that it is represented in C++ as a wide character with the value 0x2660. I don't use Unicode, but my guess is that in string form it looks like "\x60\x26" or maybe "\x2660"L.
Quote:Original post by Scet
ASCII code 3 is heart, 4 is diamond, 5 is clubs and 6 is spades

This is not standard and it depends on the font.
Quote:Original post by Zahlman
Trust me, it's not worth the effort...

I agree. Just use H, S, C, D for now. In my chess program, rather than spending time making it look pretty, I use K, Q, B, K, R, and P for the pieces.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Thanks guys. I'll try char().
By the way, I will definitely spend more time on the design, as it is greatly lacking. The graphics (if you can call it that) was just something that was bugging me and seemed like it should be a lot easier that it was.

Thanks again.

This topic is closed to new replies.

Advertisement