views:

178

answers:

3

I've finished my poker game but now I want to make it look a bit better with displaying Spades, Hearts, Diamonds and Clubs. I tried this answer: http://stackoverflow.com/questions/2094366/c-printing-ascii-heart-and-diamonds-with-platform-independent

Maybe stupid but I try:

cout << 'U+2662' << endl;

I don't know how to write it.

+1  A: 

To output a UTF-8 character, you need to encode it as hex bytes. I'll steal this link to fileinfo.com from an answer to the question you linked - if you jump to the UTF-8 representation, it says 0xE2 0x99 0xA5 and you can convert that to "\xE2\x99\xA5" as a string.

However I can't guarantee that your console will display UTF-8 so this answer might not help.

Mark Ransom
Thanks for the answer Mark. With the above string, it displays: ♥? I guess if I can find the right ones, it'll display correctly.
pocoa
I think you've just proven what I already suspected, the console doesn't use UTF-8. Did you try the code that was presented in your linked question?
Mark Ransom
Yes I did, it doesn't display the right characters.
pocoa
A: 

If you are just trying to use the old ASCII control characters in the Windows console, you can use:

cout << (char) 3 << (char) 4 << (char) 5 << (char) 6 << endl;
//hearts, diamonds, clubs, spades

This isn't Unicode, and I assume it is not very portable. I don't really know of a portable solution to your question.

This one does not work.
pocoa
Should work. Is this even a Windows console?
Hans Passant
Yes, it is Windows.
pocoa
A: 
Jon Purdy
There should be an easy way, like Mark's example.
pocoa
@pocoa: It's the same way. I'm just adding more information.
Jon Purdy
My compiler does not run this code "wcout << "\xE2\x99\xA5" << endl", says "warning: unused variable 'wcout'". I'm using Eclipse with MinGW 5.1.6.
pocoa