How to correctly display playing card unicode characters in terminal?

喜欢而已 提交于 2019-12-14 03:33:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!