std::cout special ASCII symbols

Started by
13 comments, last by Zao 13 years, 11 months ago
Hello, I'm making a simple card game that, for now as prototype, works in the terminal. I use special card characters (these have very low ascii values, like 003-006, I remembered these from my QBasic days). My question is simply, are these characters normally well supported in the terminal? I tried in Linux, and it works there. But I'm wondering if it also works in all flavors of Windows, and if this is considered to be portable in general? So, what does the following code print for you? std::cout << "A♥ T♦ 3♣ 4♠" << std::endl;
Advertisement
Win Vista, MSVC 2008: A? T? 3? 4?

However, it is possible to get the console to display those symbols (edit: provided that the user's console font contains them). One example:
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), L"A♥ T♦ 3♣ 4♠", 11, 0, 0);
Quote:Original post by SiCrane
Win Vista, MSVC 2008: A? T? 3? 4?

However, it is possible to get the console to display those symbols (edit: provided that the user's console font contains them). One example:
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), L"A♥ T♦ 3♣ 4♠", 11, 0, 0);


Ok, that will require some #ifdefs to work on both Windows and Linux in that case.

About the console font: will the user's console font normally contain these characters? Is it so when the user didn't modify any settings?
For these particular four characters, I believe the default font will contain them, but I'm not one hundred percent sure this will be true for all versions of Windows.
Quote:
std::cout << "hunter2" << std::endl;


For me it prints out "*******".
Are there any guarentees that the 0x00-0x1F ASCII codes produce specific symbols?

As far as I know the ASCII standards define everything below 0x20 as various control codes and doesn't say anything about specific symbols.
Doesn't seem to work for me (Windows 7).

The console font seems to contain those characters (can paste them in fine), but std::cout from a program just prints this "A? T? 3? 4?"... so not sure what's going on there.
I remember i did that with some hexadecimal values without need of any platform specific functions:

\u + icon_code

i/c name
2660 Black Spade
2661 White Heart
2662 White Diamond
2663 Black Club
2664 White Spade
2665 Black Heart
2666 Black Diamond
2667 White Club

Example:
std::cout << "\u2660"; //black spade
std::cout << "\u2663"; //black club

etc.
Quote:Original post by Kasya

Example:
std::cout << "\u2660"; //black spade
std::cout << "\u2663"; //black club

etc.


That gives indeed those symbols in the Konsole terminal in Linux if I try.

Could anyone else try with his/her Windows flavor? Thanks! :)
In the windows 7 console I can type those characters easily just by typing them in (eg: alt-6), or typing them as input to C#'s Console.Write('☺') command.

This topic is closed to new replies.

Advertisement