4.1 Windows10 下使用 vscode 學(xué)習(xí) C++/C

7.1 C++ 學(xué)習(xí)教程

7.2 vscode 配置

  1. 安裝 Visual Studio Code.

  2. 安裝 C++ extension for VS Code.

  3. 安裝 Mingw-w64 并將其添加到環(huán)境變量。

  4. 需要安裝 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.jsonc_cpp_properties.jsontask.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;
}

更多精彩,??Microsoft Visual Studio Code 中文手冊(cè)。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
禁止轉(zhuǎn)載,如需轉(zhuǎn)載請(qǐng)通過簡(jiǎn)信或評(píng)論聯(lián)系作者。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容