1
wcout.imbue(std::locale("chs"));
wchar_t *a = L"☻";
wcout << *a;

It's not work, why? What should I do?

Jens Gustedt
  • 76,821
  • 6
  • 102
  • 177
liuwanfu
  • 47
  • 4

3 Answers3

2

Possible errors:

  • Your compiler is possibly not recognising the L"☻" as a unicode string in the source file.
  • Your console doesn't support it

You could use the unicode character code for it instead ("\u263B"). Make sure the console supports unicode and that the font has a corresponding character for it.

It may also be easier (depending on the compiler support) to use the unicode character literals for C++ 11;

char a[] = u8"My \u263B character";
cout << a;
Niall
  • 30,036
  • 10
  • 99
  • 142
  • //char * str = "\x263B"; //wcout << str; //wcout << "\x263B"; //printf("%c","\x263B"); //puts("\x263B"); C2022: error "9787": too large for character – liuwanfu Apr 19 '16 at 06:55
  • I'm not sure how much standard unicode support is in the "wide" implementations in Windows. But as you post the code, you should use `wchar_t` and `wprintf` etc. for the wide versions of the C++ runtime. – Niall Apr 19 '16 at 07:04
0

Its the Unicode 263B source

Simple use the wchar_t a = 0x263B;

Schafwolle
  • 501
  • 3
  • 15
0

This should work (u8 since c++11):

char smiley[] { u8"\u263b" };
cout << smiley << '\n';

Or you could also just do:

char smiley[] { "\u263b" };
cout << smiley << '\n';
Andreas DM
  • 10,685
  • 6
  • 35
  • 62