为什么我的C 程序输出乱码代码
Why does my c++ program output garbled code
i使用 mingw64 来编译C 程序。但是,由于我升级到Windows 10,因此我发现我的C程序输出中文将是乱码的代码。
我遵循在线方法,在程序标题中添加代码: setConsoleoutputcp(65001(; ,然后修复。但是我认为每个C 程序都非常麻烦。我该怎么办?
我认为这是我的系统问题,Windows 7中的代码不是问题,我只想找到一个更方便的解决方案,而不是在每个文件中添加相同的代码
有代码:
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
SetConsoleOutputCP(65001);
cout << "文本" ; //Output will be garbled code if there's no line above
return 0;
}
大多数操作系统中的控制台仅期望ASCII字符输入。为了显示其他一些字符集,您必须在代码中指定这一点。setConsoleoutputcp命令设置"代码页" Windows应该从中读取。顺便说一下,并非所有版本的Windows都具有相同的代码。
请参阅此处找到的文档。
该文档建议使用EnumsystemCodepages确保该语言的代码在该系统上存在。
P.S。你的英语很好:)
编辑
我使用Visual Studio 2019在计算机上测试了您的代码,并获得了以下内容
Warning C4566 character represented by universal-character-name 'u6587' cannot be represented in the current code page (1255)
即使使用setConsoleoutputcp命令,您也添加了。我认为您需要安装Chines才能正常工作。问题在于,我没有Windows控制台的相关代码页面来寻找Char集。请参阅此答案和此答案。
相关文章:
- 我的代码输出总是得到 0
- 代码输出随机符号,我不确定出了什么问题
- 为什么当我正确执行语法时,我的代码输出为 0
- 为什么这段代码输出这么多数字
- 当我输入任何内容时,我的代码输出无效
- 我在让我的代码输出整个链表时遇到问题.它只是输出我修改过的一些文本文件,而不是整个东西
- 在 netbeans 中将C++代码输出为汇编语言
- 使用向量(STL)时,未定义的行为,请说明理性背后的以下代码输出
- 当我尝试运行此代码输出时"merge.exe has stopped working"?
- 欧拉项目 #14 代码输出未到来
- C++中的代码输出出现问题
- 如何删除此代码输出的结束空格
- 这段代码输出什么笑脸
- Win32 键转换代码输出不需要的按键
- 在 QT 中将代码输出到主窗口
- 我无法让此代码输出平均工资率,任何人都可以解释原因
- C++字母等效数字代码输出程序
- 我的代码输出重复
- c++代码输出说明
- C++代码输出负值