如何打印UTF-8字符C ++? [英] How I print UTF-8 characters C++?

查看:653
本文介绍了如何打印UTF-8字符C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何打印 C ++中的这些UTF-8字符

推荐答案

。在Windows上,您可以使用charmap.exe小程序来发现其Unicode代码点:

Well, you know it is possible because your browser could render them. On Windows you can use the charmap.exe applet to discover their Unicode code points:


  • ♠= 0x2660

  • ♣= 0x2663

  • ♥= 0x2665

  • ♦= 0x2666

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

挑战是获得一个C / C ++程序来显示它们。这不可能在任何种类的非平台特定的方式,除非你使用跨平台UI库,如Qt或wxWidgets。在Windows GUI程序中,您可以在WM_PAINT消息处理程序中这样做:

The challenge is to get a C/C++ program to display them. That's not going to be possible in any kind of non-platform specific way unless you use a cross-platform UI library like Qt or wxWidgets. In a Windows GUI program you can do it like this 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;

这篇关于如何打印UTF-8字符C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆