C ++: with Unicode console header ..?

When I try to set the console header to a string that has unicode characters, using SetConsoleTitle(), only some garbage characters are displayed in the header.
I also tried the SetConsoleTitleW () function, but this gives me the following error:

error: cannot convert 'const char*' to 'const WCHAR*' for argument '1' to 'BOOL SetConsoleTitleW(const WCHAR*)'

Any advice?

+3
source share
2 answers

You should use a wide string literal, i.e.

SetConsoleTitleW(L"DD");

L, before the quote means that it is a string wchar_t*.

Also, for completeness, I have to say that in C ++ 11 new string literal prefixes are defined:

const char a[] = u8"for a UTF-8 string.";
const char_16_t b[] = u"for a UTF-16 string.";
const char_32_t c[] = U"for a UTF-32 string.";

as usual wikipedia contains a more detailed note.

+7
source

, UTF-8 , UTF-16.

UTF-16 (.. WCHAR*), , WCHAR* (, , L"DD").

+1

All Articles