Jump to content
  • Advertisement
Sign in to follow this  
Lode

std::cout special ASCII symbols

This topic is 3011 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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! :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!