直接看官方教程:
精简教程:
输入code
创建一个文件夹,创建main.cpp,用vscode打开这个文件夹
安装插件
创建任务
选择第一个
生成task.json
双击打开main.cpp文件(选中main函数所在的文件,必须!)
先编译
点击非调试模式运行
选第二个:
选第一个:
搞定:
整个过程零配置!
只需要写一个main.cpp文件即可!
多文件编译
编译多文件修改cl.exe的参数tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "msvc build",
"type": "shell",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/nologo:",
"/Fe:",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"*.cpp"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal":"always"
},
"problemMatcher": "$msCompile"
}
]
}
修改生成文件名为固定名launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "(msvc) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "${fileDirname}/main.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true
}
]
}
双击打开main.cpp(再次选中main函数所在的文件,重要!)
终端》运行生成任务》运行》以非调试模式运行
即可: