C++ 学习与 CLion 使用:(十三)分别提供了 CLion 中使用 cout 和 cin 中文乱码的问题
上一篇 | 下一篇 |
---|---|
结构体 | 待写 |
一、cout 解决中文乱码的问题
1)方式一:
引入头文件 windows.h
,同时在 main 函数中加一句 SetConsoleOutputCP(CP_UTF8);
。
示例:
#include <iostream>
#include "windows.h" //引入指定头文件using namespace std; int main()
{SetConsoleOutputCP(CP_UTF8); //添加指定语句cout << "你好世界 --> Hello World!" << endl; return 0;
}
输出:
你好世界 --> Hello World!
2)方式二:
在 main 函数中加一句 system("chcp 65001");
。
示例:
#include <iostream>using namespace std;int main()
{system("chcp 65001"); //添加指定语句cout << "你好世界 --> Hello World!" << endl; return 0;
}
输出(会额外输出一句话):
Active code page: 65001
你好世界 --> Hello World!
二、cin 解决中文乱码的问题
其实下面说的方法也适用于上面的 cout 中文乱码的问题…
1、按住 ctrl + shift + alt + /,选择 Registry (注册表)。
2、取消勾选:run.processes.with.pty。
快捷键没反应的,要设置一下:
- 打开 CLion 设置:
File > Settings
(或Ctrl + Alt + S
)。 - 搜索
Keymap
,在右侧搜索栏输入Maintenance
。 - 设置
Ctrl + Shift + Alt + /
快捷键。