How do I print UTF-8 C ++ characters?

How do I print these UTF-8 characters in C ++?

+5
source share
3 answers

Well, you know, this is possible because your browser can display them. On Windows, you can use the charmap.exe applet to detect your Unicode code points:

  • ♠ = 0x2660
  • ♣ = 0x2663
  • ♥ = 0x2665
  • ♦ = 0x2666

The challenge is to get a C / C ++ program to display them. This will not be possible in any form of non-platform unless you use a cross-platform user interface library such as Qt or wxWidgets. In the Windows GUI program, you can do this as in the WM_PAINT message handler:

  case WM_PAINT: {
      hdc = BeginPaint(hWnd, &ps);
      HFONT hFont = CreateFont(16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, L"Arial Unicode MS");
      HGDIOBJ oldFont = SelectObject(hdc, hFont);
      RECT rc = {0, 0, 666, 16};
      DrawTextEx(hdc, L"\x2660\x2663\x2665\x2666", -1, &rc, DT_LEFT, 0);
      SelectObject(hdc, oldFont);
      DeleteObject(hFont);
      EndPaint(hWnd, &ps);
    }
    break;
0

, , UTF-8 . ++ UTF8-. uint_8.

( - UTF-8. UTF-8 .)

. sprintf("%c%c%c\n", 0xE2, 0x99, 0xA0);

+3

++: std:: wcout < L "wstr [" < wstr < L ']' < :: ;

C:   ( "% Ls\N\N", WSTR);

0

All Articles