问题
I need to print the Unicode characters for the 52 playing cards to the terminal. But when I run the code I instead get an 'A' with odd accents for the suit, followed by the card number. Based on my own reading I think the limitation is the font the terminal is using. But I'm unsure how to fix that. The terminal has no problem showing the suits themselves. For example, the program has no issue with these: ♥♠♦♣ But is unable to correctly display these: 🂡,🃂,🃆 etc
This is what gets printed out:
This is on a Cent OS 7 VM.
回答1:
#include <iostream>
int main() {
std::cout << "🂡\n"; // string literal
std::cout << "\xF0\x9F\x82\xA1\n"; // UTF-8 encoded octets
}
If you have the character in a string, you need to encode it yourself, see https://stackoverflow.com/questions/tagged/c%2b%2b%20utf-8.
回答2:
Not sure where you got the code 1F0. Mine works:
int main() {
std::cout << "Hello World!\n";
std::cout << "\u2660\u2661\u2662\u2663\u2664\u2665\u2666\u2667\n";
}
Run it online! https://repl.it/repls/AltruisticMixedTask
I looked up the code here: https://unicodelookup.com/#suit/1
来源:https://stackoverflow.com/questions/55963564/how-to-correctly-display-playing-card-unicode-characters-in-terminal