C++没有按预期打印表情符号
我有以下程序摘录
int main(){
cout << "1) ✊\n";
cout << "2) ✋\n";
cout << "3) ✌️\n";
}
,但在运行它时,我收到如下奇怪的文本
====================
rock paper scissors!
====================
1) 
2) 
3) ԣÅ
这似乎与我的终端无关,而是与编译结果相关,因为如果我运行 echo ✊
它显示如预期。
我目前正在使用以下编译命令和编译器版本 g++ *.cpp -o rock_paper_scissors.exe
g++.exe(Rev9,由 MSYS2 项目构建)11.2.0 版权所有 (C) 2021 自由软件基金会,Inc.
最后,请注意,它之前按预期工作,但在某些时候,它停止工作,我在使用 system("pause")
之后注意到我猜想可能已经更改了编译配置上的某些内容,因为这是仅限 Windows 的命令,我删除了这样的代码但仍然存在问题。
您可以在此处查看其余代码:https://github.com/guillene/RockPaperScissors
I have the following extract of a program
int main(){
cout << "1) ✊\n";
cout << "2) ✋\n";
cout << "3) ✌️\n";
}
But at the time I run it I get strange texts like the following
====================
rock paper scissors!
====================
1) 
2) 
3) ԣÅ
This seems not to be related to my terminal but instead to a compilation result because if I run echo ✊
it shows as expected.
I'm currently using the following compilation commands and compiler versiong++ *.cpp -o rock_paper_scissors.exe
g++.exe (Rev9, Built by MSYS2 project) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
Finally, note that it was working before as expected, but at some point, it stopped working, I noticed after I used system("pause")
which I'm guessing may have changed something on the compilation configurations as this is a Windows-only command, I delete such piece of code and still having the issue.
You can see the rest of the code here: https://github.com/guillene/RockPaperScissors
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的终端字体支持表情符号并且您不想编写太多代码(例如从 cout 切换到 wcout),则可以使用下面的 windows api 函数。
请参阅:https://learn.microsoft.com/en-us/windows/控制台/setconsoleoutputcp
If your terminal font supports emojis and you don't want to write much code (like switching from cout to wcout), you can use the windows api function below.
see: https://learn.microsoft.com/en-us/windows/console/setconsoleoutputcp