How can I print unicode characters (e.g. specifically, the 'suit' symbols,
i.e. hearts clubs diamonds spades), to the console?

I've tried every possible manipulation of wchar_t I can think of and nothing
will work. To make it worse, VB.NET can do it - so I know it's not a
limitation of the console. How can I do this in (unmanaged) C++?
Thanks

Re: unicode characters on console? by Eric

Eric
Tue Feb 27 11:07:23 CST 2007

On Tue, 27 Feb 2007 10:41:24 -0600, Ben <Ben@discussions.microsoft.com>
wrote:

> How can I print unicode characters (e.g. specifically, the 'suit'
> symbols,
> i.e. hearts clubs diamonds spades), to the console?
>
> I've tried every possible manipulation of wchar_t I can think of and
> nothing
> will work. To make it worse, VB.NET can do it - so I know it's not a
> limitation of the console. How can I do this in (unmanaged) C++?
> Thanks

Those characters aren't unicode, they are the ancient version of DOS's way
to represent start/end transmission characters and other similarly low
ASCII values. For example:

#include <iostream>

using namespace std;

int main(void) {
cout << '\003' << '\004' << '\005' << '\006' << endl;
system("pause");
return 0;
};

Re: unicode characters on console? by Jochen

Jochen
Tue Feb 27 11:11:20 CST 2007

Hi Ben!
> How can I print unicode characters (e.g. specifically, the 'suit' symbols,
> i.e. hearts clubs diamonds spades), to the console?

Just do it!
But you need to have the correct console-font! The default font is not
able to display this characters. You need to use the "Lucidia Console" font.

> I've tried every possible manipulation of wchar_t I can think of and nothing
> will work. To make it worse, VB.NET can do it - so I know it's not a
> limitation of the console. How can I do this in (unmanaged) C++?

Also the best way is to use WriteConsoleW to do the output. If you use
printf, it will use the default-culture to transform the characters to
ANSI...

See: wprintf/wcout has no UNICODE support
http://blog.kalmbachnet.de/?postid=23

In VC2005 there should be better support for console output, but I have
not tried it yet...

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/

Re: unicode characters on console? by Tamas

Tamas
Tue Feb 27 11:47:32 CST 2007

Ben wrote:
> How can I print unicode characters (e.g. specifically, the 'suit' symbols,
> i.e. hearts clubs diamonds spades), to the console?

DWORD dummy;
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"\u2660", 1, &dummy, 0);

> I've tried every possible manipulation of wchar_t I can think of and nothing
> will work.

It's a known problem:
http://blog.kalmbachnet.de/?postid=23

Tom

Re: unicode characters on console? by Tamas

Tamas
Tue Feb 27 13:09:00 CST 2007

Jochen Kalmbach [MVP] wrote:

> In VC2005 there should be better support for console output, but I have
> not tried it yet...

If there is, I don't know how to do it, because wcout and wprintf still
completely skip Unicode characters with my VC++2005 SP1. WriteConsoleW
(unmanaged) and Console::WriteLine (managed) work, though.

Tom

Re: unicode characters on console? by Jochen

Jochen
Tue Feb 27 13:52:08 CST 2007

Hi Tamas!

>> In VC2005 there should be better support for console output, but I
>> have not tried it yet...
>
> If there is, I don't know how to do it, because wcout and wprintf still
> completely skip Unicode characters with my VC++2005 SP1.

You need to eanble this feature with "_setmode":

#define UNICODE
#define _UNICODE
#include <tchar.h>
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
int _tmain()
{
_setmode(_fileno(stdout), _O_U16TEXT);
_tprintf(_T("A\x0424") _T("C\n"));
}

Then everything works as expected!

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/

Re: unicode characters on console? by Jochen

Jochen
Tue Feb 27 13:59:37 CST 2007

Hi Tamas!
>> In VC2005 there should be better support for console output, but I
>> have not tried it yet...
>
> If there is, I don't know how to do it, because wcout and wprintf still
> completely skip Unicode characters with my VC++2005 SP1.

See: wprintf/wcout and unicode characters in VS2005
http://blog.kalmbachnet.de/?postid=98

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/