安装vs code
https://code.visualstudio.com/
安装c++插件
下载编译器
常用的有
- MinGW:https://sourceforge.net/projects/mingw-w64/files/
- TDM-GCC:https://www.baidu.com/link?url=QQV-jAj2kw6xxsv4fxrq4Si8mjkPWJXrtewUJujBbMswrb598qlYZzLCW-IS45wD&wd=&eqid=b24fd34700109ae00000000460c0b422
选择一个安装后记住地址
配置环境
-
打开任一文件夹,并建立test.cpp
如下图所示,插件已经安装完成,关键字自动高亮,点击F5运行,自动跳转到了launch.json
-
编辑launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gbd) launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false, //修改此项,让其弹出终端
"MIMode": "gdb",
"miDebuggerPath": "D:\\TDM-GCC-64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++" //修改此项
}
]
}
- 在.vscode下再创建一个task.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++", //修改此项
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\TDM-GCC-64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}
输出到terminal
- 问题
尝试了两天,没法把输出到自带终端上,很崩溃 - 解决
安装一个插件code runner,在setting.json中加一句"code-runner.runInTerminal": true,
强烈安利,支持多语言一键运行