Hi,
I want to output chess symbols from unicode to console in c++, please tell me how to do that.
Im using Dev c++, windows8 and console.
Im just a beginner so please keep it simple for me (also tell me the libraries to include please)

Edited 4 Years Ago by tayyabatiq

Im just a beginner so please keep it simple for me

The problem is that it's not simple. You can tell C++ to write Unicode characters until you're blue in the face, but if the console isn't set up to support Unicode or using a font that supports those characters, you won't get the correct output. It's more of a limitation of the command prompt than C++.

I'd suggest using Google, but this page is a good starting point as well. Note that cout/wcout correspond roughly to printf/wprintf.

Edited 4 Years Ago by deceptikon

I've been searching for days, and everyone keeps telling to change font to Lucida Console Unicode, use wide characters and output using wcout.
But the thing is:
1.How to change font to Lucida Console Unicode?

2.If i try to just copy/paste the character (like ♔) in Dev C++, there appears '?' instead of '♔'

3.There must be a function for UNICODE like char(x) is for ASCII

How to change font to Lucida Console Unicode?

Right click on the console window and choose Properties. From there you can change the font.

If i try to just copy/paste the character (like ♔) in Dev C++, there appears '?' instead of '♔'

Yes, that's what happens when the output medium (the text editor in this case) doesn't support Unicode or uses a font that doesn't support the character.

There must be a function for UNICODE like char(x) is for ASCII

Yes, it's called a wide character or string:

L'<character goes here>'
L"<string goes here>"

But that has exactly nothing to do with your problem, which is configuring the output device to handle Unicode. Did you read the link I gave you?

Edited 4 Years Ago by deceptikon

Thankyou for replying

Yes i've read that page before. But as i said before, i'm just a beginner. So i did not get a word that was written there. I'm very much confused right now.. Can you send me a sample code for doing this task? including the libraries..

Edited 4 Years Ago by tayyabatiq

Can you send me a sample code for doing this task?

Since you clearly didn't find the obvious code examples on the links you say you read, here:

#include <wchar.h>
#include <windows.h>

int main()
{
    const wchar_t *white = L"♔♕♖♗♘♙\r\n";
    const wchar_t *black = L"♚♛♜♝♞♟\r\n";

    WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), white, wcslen(white), 0, 0);
    WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), black, wcslen(black), 0, 0);
}

Shall I assume that your next complaint will be that you're seeing nothing but question marks or squares in the command prompt? Because that would take us full circle on your complete failure to comprehend all of the useful information you've been given.

including the libraries..

They're all built into the compiler.

Edited 4 Years Ago by deceptikon

How can i use that function with an integer value?
cout<<L"9812"; and any other integer value displays: 0x401290

L'<character goes here>'
L"<string goes here>"

It doesn't work since pasting those symbols in Dev C++ only pastes question marks.

const wchar_t *white = L"♔♕♖♗♘♙\r\n";
const wchar_t *black = L"♚♛♜♝♞♟\r\n";

u'9812' (C++11 only) or L'\x9812'. The former is preferred if supported. Some compilers also offer a unicode escape such as L'\u9812'. For multiple characters use the string variant L"<character codes go here>".

It doesn't work since pasting those symbols in Dev C++ only pastes question marks.

Woohoo! And we've come full circle. Yes, it works fine. Dev-C++ just doesn't know how to display those characters. Did you read anything I've typed in this thread?

I've tried your code but all it does is display question marks in the console!

@NathanOliver: i've changed the font to Lucida Console. I hope that's the correct one.

@deceptikon: just trolling :P

@deceptikon: just trolling :P

Then you don't need anymore help? Awesome, that frees up some of my time for more productive pursuits. Thanks!

This article has been dead for over six months. Start a new discussion instead.