博主使用CLion如果里面有中文经常会遇到输出乱码问题,本篇博文将告诉你多种问题的解决方案。
问题描述
我们新建一个CLion工程:
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
std::cout << "你好,中文!" << std::endl;
return 0;
}
从控制台我们会得到:
Hello, World!
浣犲ソ锛屼腑鏂囷紒
Process finished with exit code 0
解决方案一:CLion的简单设置
CLion -> File -> Settings -> Editor -> File Encodings
![在这里插入图片描述](https://img-blog.csdnimg.cn/65a0ceee54eb4944b6fd902f6c7531bc.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAeW16aHUzODU=,size_20,color_FFFFFF,t_70,g_se,x_16)
如果是Windows,右下角改成GBK:
![在这里插入图片描述](https://img-blog.csdnimg.cn/e9891a9ab31c490a93a01a63aaf62430.png)
如果是Linux,右下角改成UTF-8:
![在这里插入图片描述](https://img-blog.csdnimg.cn/8ad9f35fb11f460a92b5c0d29979eeda.png)
也就是我们用UTF-8编码,输出在windows中是GBK,而输出在Linux中是UTF-8。
见证奇迹
![在这里插入图片描述](https://img-blog.csdnimg.cn/6687594a54a0449b82ed49add9546e1c.png)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)