一、VSCode介绍
Visual Studio Code(简称VSCode)是一款由微软开发的免费、开源的跨平台代码编辑器,支持Windows、macOS和Linux系统。 VSCode以其轻量级、高性能和强大的扩展性而广受开发者喜爱,支持多种编程语言,如JavaScript、Python、C++等。
二、VSCode下载
下载链接:https://pan.quark.cn/s/19a303ff81fc
三、VSCode安装
1.解压安装文件:双击打开并安装VSCode
2.勾选我同意协议:然后点击下一步
3.选择目标位置:点击浏览
4.选择D盘安装:然后点击确定
建议安装在C盘以外的其他磁盘。
5.点击下一步
6.选择开始菜单文件夹:点击下一步
7.按下面提示勾选,然后点击下一步
1)【通过 Code 打开操作添加到windows资源管理器文件上下文菜单】、【通过 Code 打开操作添加到windows资源管理器目录上下文菜单】 把这个两个勾选上,可以对文件使用鼠标右键,选择VSCode 打开。
2、【将 Code 注册为受支持的文件类型的编辑器】,不建议勾选,这样会默认使用VSCode打开支持的相关文件,文件图标也会改变。
3、【添加到PATH(重启后生效)】,建议勾选,这样可以使用控制台打开VSCode 了。
8.点击安装
9.等待安装完成
此步骤预计安装时长2分钟左右。
10.点击完成:运行VSCode
四、配置中文界面
1.点击下图所示按钮
2.搜索Chinese:然后点击install
3.点击【Change Language and Restart】
4.点击后自动重启软件:配置中文成功
五、配置调试功能
1.在桌面创建一个文件夹
文件夹名字随意命名为英文(注意不可以用中文!),以后的C/C++代码文件都要放在这个文件夹里才可以正常调试。
2.进入VSCode,点击左上角文件 -> 新建文本文件
3.然后打开刚刚建的文件夹,选择信任父级文件夹
4.点击这个图标新建一个文件夹
命名为.vscode(注意必须是这个名字!)
5.创建完成后再点击.vscode文件夹并新建四个文件
文件名如下:
c_cpp_properties.json
launch.json
settings.json
tasks.json
6.复制粘贴这四个文件的内容
1)c_cpp_properties.json,注意compilerPath这一项要把路径改成刚才g++的安装路径:找到刚刚的安装文件夹->MinGW->bin->g++,exe ,然后复制或者手动把g++.exe的路径敲上去,格式要跟上面代码段一样
{
"configurations": [
{
"name": "Win64",
"includePath": ["${workspaceFolder}/**"],
"defines": ["_DEBUG", "UNICODE", "_UNICODE"],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:/MinGW/bin/g++.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
2)launch.json,注意miDebuggerPath这一项也要把路径改成刚才g++的安装路径:找到刚刚的安装文件夹->MinGW->bin->gdb.exe ,然后复制或者手动把gdb.exe的路径敲上去,格式要跟上面代码段一样
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"preLaunchTask": "g++",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
3)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
}
4)tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "g++",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe"
],
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
保存上面四个文件后,配置就完成了!以后的C/C++代码文件必须放在这个Code文件夹里,或者说有.vscode文件夹的文件夹里,如果调试放在其他位置的代码文件会报错!
版权归原作者 ZHOUPUYU 所有, 如有侵权,请联系我们删除。