7.1 C++ 學(xué)習(xí)教程
7.2 vscode 配置
安裝 Mingw-w64 并將其添加到環(huán)境變量。
需要安裝 Visual Studio 2019
7.2.1 識(shí)別編譯路徑
令 vscode 識(shí)別 MSVC,快捷鍵:Ctrl+Shift+P 打開配置界面:

這樣打開了 UI 配置界面:

這樣便在
.vscode 目錄下生成文件 c_cpp_properties.json
7.2.2 創(chuàng)建一個(gè) build task
選擇 查看 --> 命令面板...:

輸入 task 并選擇 `:



vscode 創(chuàng)建了一個(gè)最小化的 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 用于調(diào)試時(shí)使用的名稱,The group value specifies that this task will be run when you press Ctrl+Shift+B。
7.2.3 debug 設(shè)置
選擇 調(diào)試--> 添加配置:

接著選中 C/C++ (Windows):

便會(huì)生成 launch.json 文件。
更多內(nèi)容參考:Configure debug settings
7.2.4 測(cè)試
依據(jù)上文在 .vscode 生成的 launch.json 、c_cpp_properties.json、task.json 便可以編寫并調(diào)試 C++/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;
}