I'm trying to make my program work with unicode characters. I'm using Visual Studio 2010 on a Windows 7 x32 machine.
What I want to print is the queen symbol ("\ul2655") and it just doesn't work. I've set my solution to use unicode.
This is my sample code:
#include <iostream>
using namespace std;
int main()
{
SetConsoleOutputCP(CP_UTF8);
wcout << L"\u2655";
return 0;
}
Also, I've tried many other suggestions, but nothing worked. (eg. change the cmd font, apply chcp 65001, which is the same as SetConsoleOutputCP(CP_UTF8), etc).
What is the problem? It's for the first time I encounter such a situation. On linux, it's different.
Thank you.
Once I managed to print chess pieces on the console; there are several complexities involved here.
First of all, you have to enable UTF-16 mode on stdout; this is described here as well as here, and it's exactly as Mehrdad explained.
Then, even if the output reached the console correctly, on the console you may get garbage instead of the intended characters; this comes form the fact that, at least on my machine (Windows 7), the default console font doesn't support the chess pieces glyphs.
To fix this, you have to choose a different TrueType font which supports them, but to make such a font available you have to go through some hoops; personally, I found out that DejaVu Sans Mono works just fine.
So, at this point, your code should work, and code like this (the example I wrote in the past to test this issue):
should work equally well on Windows and Linux.
Now you still have a problem: the glyphs will be too small to be meaningful in any way:
this can be solved only by enlarging the console font, but you'd get all the other characters to be way too big to be usable. Thus, all in all, probably the best fix is just to write a GUI application.
Try this instead