欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 金融 > vscode 配置c/c++环境 中文乱码

vscode 配置c/c++环境 中文乱码

2025/8/30 7:14:33 来源:https://blog.csdn.net/weixin_51323049/article/details/144995355  浏览:    关键词:vscode 配置c/c++环境 中文乱码
D:\MIscrobingDownload\mingw64\bin

mingw配置到环境变量中
在这里插入图片描述
测试一下,按win+r输入cmd打开终端

gcc -v
g++ -v

安装插件

在这里插入图片描述

run code

因为run code 插件配置实质上是用它提供的指令进行编译执行,因此无法直接使用断点调试功能,需要对配置进行一定的更改

如果出现乱码问题
第一:
源文件 .cpp 修改为 UTF-8 编写和保存时的格式
第二:
OUTPUT输出时不乱码编译时 UTF-8格式
在这里插入图片描述
在这里插入图片描述

一 终端错误 terminal 改为UTF-8
可以找到code runner插件,点击扩展设置,随便点击一个打开setting.json文件,修改下配置命令
在这里插入图片描述在这里插入图片描述
vscode 的设置里面的setting.json
在这里插入图片描述

在这里插入图片描述
配置 GBK 改为UTF-8 因为 UTF-8 能够兼容各种字符 终端输出中文不出错

总结:
terminal :
gbk编写和保存代码
终端 UTF-8 用 chcp 看 chcp 65001
OUTPUT
编写和保存代码用UTF-8
输出不乱码

设置
修改终端字体大小
terminal.integrated.fontSize
二 .cpp文件乱码 GBK
在这里插入图片描述

  1. c_cpp_properties.json
{"configurations": [{"name": "Win32","includePath": ["${workspaceFolder}/**"],"defines": ["_DEBUG", "UNICODE", "_UNICODE"],"windowsSdkVersion": "10.0.17763.0","compilerPath": "D:\\MIscrobingDownload\\mingw64\\bin\\x86_64-w64-mingw32-g++.exe",   /*修改成自己bin目录下的g++.exe,这里的路径和电脑里复制的文件目录有一点不一样,这里是两个反斜杠\\*/"cStandard": "c11","cppStandard": "c++17","intelliSenseMode": "${default}"}],"version": 4
}
  1. launch.json
{"version": "0.2.0","configurations": [{"name": "g++.exe build and debug active file","type": "cppdbg","request": "launch","program": "${fileDirname}\\exe\\${fileBasenameNoExtension}.exe","args": [],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": false,"MIMode": "gdb","miDebuggerPath": "D:\\MIscrobingDownload\\mingw64\\bin\\gdb.exe",// 自己的mingw gdb.exe"setupCommands": [{"description": "Enable pretty-printing for gdb",// 为 gdb 启用整齐打印"text": "-enable-pretty-printing","ignoreFailures": true}],"preLaunchTask": "task g++"}  //,// 生成 exe 文件/*   {"name": "C/C++: cpp.exe 生成和调试活动文件","type": "cppdbg","request": "launch","program": "${fileDirname}\\${fileBasenameNoExtension}.exe","args": [],"stopAtEntry": false,"cwd": "${fileDirname}","environment": [],"externalConsole": false,"MIMode": "gdb","miDebuggerPath": "D:\\Chromedownload\\mingw\\MinGW\\bin\\gdb.exe","setupCommands": [{"description": "为 gdb 启用整齐打印","text": "-enable-pretty-printing","ignoreFailures": true},{"description": "将反汇编风格设置为 Intel","text": "-gdb-set disassembly-flavor intel","ignoreFailures": true}],"preLaunchTask": "C/C++: cpp.exe 生成活动文件"}
*/]
}
  1. settings.json
{"files.associations": {"*.py": "python","iostream": "cpp","*.tcc": "cpp","string": "cpp","unordered_map": "cpp","vector": "cpp","ostream": "cpp","new": "cpp","typeinfo": "cpp","deque": "cpp","initializer_list": "cpp","iosfwd": "cpp","fstream": "cpp","sstream": "cpp","map": "c","stdio.h": "c","algorithm": "cpp","atomic": "cpp","bit": "cpp","cctype": "cpp","clocale": "cpp","cmath": "cpp","compare": "cpp","concepts": "cpp","cstddef": "cpp","cstdint": "cpp","cstdio": "cpp","cstdlib": "cpp","cstring": "cpp","ctime": "cpp","cwchar": "cpp","exception": "cpp","ios": "cpp","istream": "cpp","iterator": "cpp","limits": "cpp","memory": "cpp","random": "cpp","set": "cpp","stack": "cpp","stdexcept": "cpp","streambuf": "cpp","system_error": "cpp","tuple": "cpp","type_traits": "cpp","utility": "cpp","xfacet": "cpp","xiosbase": "cpp","xlocale": "cpp","xlocinfo": "cpp","xlocnum": "cpp","xmemory": "cpp","xstddef": "cpp","xstring": "cpp","xtr1common": "cpp","xtree": "cpp","xutility": "cpp","stdlib.h": "c","string.h": "c"},"editor.suggest.snippetsPreventQuickSuggestions": false,"aiXcoder.showTrayIcon": true}
  1. tasks.json 定义任务配置

再次强调:以后的C/C++代码文件必须放在这个Code文件夹里,或者说有.vscode文件夹的文件夹里,如果调试放在其他位置的代码文件会报错!
在这里插入图片描述
在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词