4.1 Windows10 下使用 vscode 学习 C++/C

7.1 C++ 学习教程

7.2 vscode 配置

  1. 安装 Visual Studio Code.

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

  3. 安装 Mingw-w64 并将其添加到环境变量。

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

更多精彩,👀Microsoft Visual Studio Code 中文手册

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
禁止转载,如需转载请通过简信或评论联系作者。

推荐阅读更多精彩内容