7.1 C++ 学习教程
7.2 vscode 配置
安装 Mingw-w64 并将其添加到环境变量。
需要安装 Visual Studio 2019
7.2.1 识别编译路径
令 vscode 识别 MSVC,快捷键:Ctrl+Shift+P 打开配置界面:

这样打开了 UI 配置界面:

这样便在
.vscode 目录下生成文件 c_cpp_properties.json
7.2.2 创建一个 build task
选择 查看 --> 命令面板...:

输入 task 并选择 `:



vscode 创建了一个最小化的 tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "msbuild",
"args": [
// Ask msbuild to generate full paths for file names.
"/property:GenerateFullPaths=true",
"/t:build",
// Do not generate summary otherwise it leads to duplicate errors in Problems panel
"/consoleloggerparameters:NoSummary"
],
"group": "build",
"presentation": {
// Reveal the output only if unrecognized errors occur.
"reveal": "silent"
},
// Use the standard MS compiler pattern to detect errors, warnings and infos
"problemMatcher": "$msCompile"
}
]
}
label 用于调试时使用的名称,The group value specifies that this task will be run when you press Ctrl+Shift+B。
7.2.3 debug 设置
选择 调试--> 添加配置:

接着选中 C/C++ (Windows):

便会生成 launch.json 文件。
更多内容参考:Configure debug settings
7.2.4 测试
依据上文在 .vscode 生成的 launch.json 、c_cpp_properties.json、task.json 便可以编写并调试 C++/C 程序了。
测试代码 test.cpp:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> msg {"Hello", "C++", "World", "from", "VS Code!"};
for (const string& word : msg)
{
cout << word << " ";
}
cout << endl;
}