Hiya,

Im trying make a simple cards game and i was wondering how in c++ can i use the characters ♠ ♣ ♥ ♦ , i think it would be betetr than me printing out the words each time, Are these in some extended character set anywhere? i tried googling but i could only find html versions like &spades; or xsl <spade/>.

Anyone know how i could print the ♠ ♣ ♥ ♦ symbols in a console application?

Thanks for your time

Dani AI

Generated

The suit symbols are Unicode characters, not part of plain ASCII: BLACK SPADE SUIT (U+2660), BLACK CLUB SUIT (U+2663), BLACK HEART SUIT (U+2665) and BLACK DIAMOND SUIT (U+2666). showed the single-byte console trick and showed literal printing; both can work, but they depend on the terminal/code page. For portability prefer emitting Unicode (UTF-8 or UTF-16) and let the terminal/font render the glyphs.

Save your source as UTF-8 and, on UTF-8-capable terminals, print the Unicode escapes. Example (C++11+):

#include <iostream>
#include <clocale>

int main() {
    std::setlocale(LC_ALL, "");
    std::cout << u8"\u2665 \u2666 \u2663 \u2660\n";
    return 0;
}

This prints the four suits as UTF-8 bytes when the terminal accepts UTF-8.

Notes and troubleshooting: older Windows cmd.exe uses legacy code pages and may not show these glyphs; two reliable Windows options are (a) use Win32 wide APIs such as WriteConsoleW to send UTF-16, or (b) switch the console to UTF-8 (SetConsoleOutputCP(CP_UTF8)) and emit UTF-8. If you see question marks or empty boxes, the problem is either an encoding mismatch or the chosen console font lacks the glyphs. For maximum compatibility in simple text UIs, fall back to letters like H S D C or simple ASCII art.

Recommended Answers

All 3 Replies

These should output the same characters.

char *hearts  = "\x03";  //♥
char *diamond = "\x04";  //♦
char *clubs   = "\x05";  //♣
char *spades  = "\x06";  //♠
cout << "♠ ♣ ♥ ♦" << endl;

does the trick.

Nice one,
I had made a function that looped through all the 0-256 char's but coudlent find it, maybe it was because i was using it as unsigned i dunno, but that works perfect thanks allot :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.