I\'m developing a card playing game and would like to print out the symbol for hearts, diamonds, spades and clubs. My target platform will be Linux.
In Windows, I k
On Linux, you can almost always write UTF-8 to stdout and Unicode characters will be displayed beautifully.
#include
const char heart[] = "\xe2\x99\xa5";
int main() {
std::cout << heart << '\n';
return 0;
}
You can find UTF-8 encodings of Unicode characters on sites like fileformat.info (search that page for "UTF-8 (hex)").
Another way is to use wide characters. You first need to call setlocale
to set things up. Then just use wchar_t
instead of char
and wcout
instead of cout
.
#include
#include
const wchar_t heart[] = L"\u2665";
int main() {
setlocale(LC_ALL, "");
std::wcout << heart << L'\n';
return 0;
}