【问题标题】:Win32 C++: How to print a smily face ☻ onto console output stream? [duplicate]Win32 C++:如何在控制台输出流上打印笑脸☻? [复制]
【发布时间】:2015-12-12 11:49:20
【问题描述】:

我试过setlocale、wchar、普通char……怎么定义:

char c = '☻'
cout << c << endl;

打印到控制台上(这与 VS2012 和 http://ideone.com/LJtDUz 有关)

【问题讨论】:

标签: c++


【解决方案1】:

问题是windows默认不处理Unicode字符,windows控制台也无法显示。

我在This CPP Thread找到的解决方案如下:

#include <fcntl.h>
#include <io.h>
#include <iostream>

int
main(int argc, char* argv[])
{
    wchar_t* c = L"☻"; /* needed because the project is using 'Unicode Character Set' */

    _setmode(_fileno(stdout), _O_WTEXT); /* set stdout to UTF16 */
    std::wcout << c << std::endl; /* use a wide cout call to output characters */

    getchar();

    return 0;
}

当您尝试直接在代码中使用 符号时,Windows 会告诉您我需要将您的文件转换为Unicode,请确保接受并使用Unicode Character Set 作为您的项目字符集类型.

【讨论】:

  • 对它的工作感到惊讶。 VS 默默地将 ansi 换成 unicode 换成字符?
  • @user4581301 老实说,我不是 100% 高兴这个答案解释了一切(即使它是正确的),所以我正在寻找现在深处到底发生了什么。
  • "序列 \x002 是笑脸的 unicode 表示"。不,这不对。在 Unicode 发明之前的 1980 年代,最初的 IBM PC 恰好显示为笑脸,这是一个控制字符。直到今天,微软操作系统仍在继续模仿它。它与 Unicode 字符☻无关。
  • @n.m.感谢您的评论您是正确的,我将删除答案的那部分。我遇到了一个实际的答案,我将很快发布。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-06-05
  • 2013-06-15
  • 2023-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多