std::cout special ASCII symbols

Started by
13 comments, last by Zao 13 years, 12 months ago
Quote:Original post by Lode
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! :)


Nope, still ?'s for me... (Win 7).

EDIT: This seems to work though:

int main(int, char*[]) {	char heart = '\3';	char diamond = '\4';	char club = '\5';	char spade = '\6';		std::string all = "\3\4\5\6";		std::cout << heart << diamond << club << spade << std::endl;	std::cout << all << std::endl;}


[Edited by - sprite_hound on April 23, 2010 2:26:37 PM]
Advertisement
Quote:Original post by sprite_hound
Quote:Original post by Lode
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! :)


Nope, still ?'s for me... (Win 7).

EDIT: This seems to work though:

int main(int, char*[]) {	char heart = '\3';	char diamond = '\4';	char club = '\5';	char spade = '\6';		std::string all = "\3\4\5\6";		std::cout << heart << diamond << club << spade << std::endl;	std::cout << all << std::endl;}


What could be an explanation for that? This is strange... Why would std::cout print characters in different ways in the terminal depending on how you give it as string?
Windows terminals use the Terminal font, which only has support for the IBM character set. When you paste "A♥ T♦ 3♣ 4♠" into your IDE, you're using the Unicode counterparts, which, under the Terminal font that Windows uses, shows up as '?'. I suspect that a combination of changing the Windows terminal font to a non-bitmap font (such as Arial 'n' such) or compiling with _UNICODE or using wcout and wchar_t literals will fix the problem.
Aww dammit, the '\3' variant shows up wrong in Linux, it becomes a small box with "0003" in it.

Anyway, easily solved by OS-dependent #ifdefs :)

Thanks for the info.
The console subsystem in Windows is a magical and special place. If you're dead set on doing a console application, the best bet is to follow the advice in this and this blog post.

As for narrow output streams like std::cout, they pass through whatever bytes you pass them, so if you feed it UTF-8 encoded text, they will output UTF-8 encoded text. In the case of Linux, if the terminal locale is set to UTF-8, it'll display properly.

In the case of the Windows console, the data displayed will be shown in the current system codepage, unless you've selected another codepage into it.

To make it is hell. To fail is divine.

This topic is closed to new replies.

Advertisement