c++ - 我无法使用 C++ 在 Visual Studio 2019 中打印无穷大符号
问题描述
我正在尝试打印无穷大符号(∞),但我不断收到垃圾。我已经尝试了这里提到的所有内容,但没有任何效果。
我想要完成的是这个
modifies strength by 9 ∞
我试过了
printf ("%c", 236);
printf ("%c", 236u);
我得到
modifies strength by 9 ì
我试过了
printf("∞");
我得到
modifies strength by 9 ?
我试过这个
if ( paf->duration == -1 ){
setlocale(LC_ALL, "en_US.UTF-8");
wprintf(L"%lc\n", 8734);
ch->printf("∞");
只是想看看我是否可以让 wprintf 打印它,但它完全忽略了 setlocale 和 wprintf 并且仍然给了我
modifies strength by 9 ?
我试过了
if ( paf->duration == -1 ){
std::cout << "\u221E";
ch->printf("∞");
但是得到了这个警告和错误
Error C2664 'int _CrtDbgReportW(int,const wchar_t *,int,const wchar_t *,const wchar_t *,...)': cannot convert argument 5 from 'int' to 'const wchar_t *' testROS1a C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\malloc.h 164
Warning C4566 character represented by universal-character-name '\u221E' cannot be represented in the current code page (1252) testROS1a C:\_Reign of Shadow\TEST\src\CPP\act_info.cpp 3724
我无法做出正面或反面。我已经用尽了我的知识范围,所以有人知道如何做到这一点吗?
解决方案
这在我的机器 Windows + 代码页 (1252) 上起到了作用,但不确定这有多普遍。我从来没有真正用过 unicode/localization 的东西。而且似乎总是还有一个问题。
#include <iostream>
#include <io.h>
#include <fcntl.h>
const wchar_t infinity_symbol = 0x221E;
int main()
{
// enable windows console to unicode
_setmode(_fileno(stdout), _O_U16TEXT);
std::wcout << infinity_symbol;
}
推荐阅读
- apache-spark - 用于预测的 Spark 中的 PMML 执行
- ssh - Plotly 和 JupyterLab:图表未从远程服务器显示
- java - 构造函数和实例变量之间的区别
- php - 如何更有效地比较大海捞针
- prolog - 优化 clp(FD) 标记
- asp.net-core - Kestrel HTTPS 重定向导致没有响应,调试日志“应用程序在未读取整个请求正文的情况下完成”。
- python-3.x - Python:写入文件变音符号作为转义字符序列
- assembly - 汇编语言中的结构
- ios - 更新到最新版本的 Visual Studio 和 Xamarin 后无法启动应用程序
- sql - SQL:将 table1 和 table2 与合并的行链接,然后链接到 table3