开个大课题:C++
第一步:下载安装MinGW
官网:http://mingw-w64.org/doku.php/download
下载安装包名:mingw-w64-install.exe
安装步骤省略(选x86_64即可)。
添加bin文件夹路径到环境变量:
C:\Program\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin
验证:
gcc --version
第二步:配置.json,测试hello.cpp
单击:run => start debugging
launch.json:
// Configuring tasks.json for C/C++ debugging
// author: huihut
// repo: https://gist.github.com/huihut/9548fe7e1084cf8e844120c5668b8177
// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${fileBasename}: the current opened file's basename
// ${fileDirname}: the current opened file's dirname
// ${fileExtname}: the current opened file's extension
// ${cwd}: the current working directory of the spawned process
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"preLaunchTask": "build",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}]
}
tasks.json:
// Configuring tasks.json for C/C++ debugging
// author: huihut
// repo: https://gist.github.com/huihut/887d3c28db92617bd5148c20a5ff112a
// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${fileBasename}: the current opened file's basename
// ${fileDirname}: the current opened file's dirname
// ${fileExtname}: the current opened file's extension
// ${cwd}: the current working directory of the spawned process
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"windows": {
"command": "g++",
"args": [
"-ggdb",
"\"${file}\"",
"--std=c++11",
"-o",
"\"${fileDirname}\\${fileBasenameNoExtension}.exe\""
]
}
}
]
}
测试代码:
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
int a, b, c;
std::cout << "hello VsCode!" << std::endl;
cin >> a >> b;
cout << "a+b=" << a+b << endl;
cin >> c;
return 0;
}
步骤:
- 新建项目(Project)
- 在项目中添加源程序文件(Source File)
- 编辑(Edit)源程序
- 组建(Build)
- 编译(Compile) + 连接(Link)
- 运行(Run)