VScode 配置c++环境

参考

https://code.visualstudio.com/docs/cpp/config-mingw

https://zhuanlan.zhihu.com/p/77645306 主要

https://blog.csdn.net/qq_41684261/article/details/86322737

官网给出的配置过程稍微复杂一些

以下内容参考  知乎 唐铭   https://zhuanlan.zhihu.com/p/77645306   

1.安装vscode

官网下载安装即可

2.安装mingw64

建议安装离线版

https://sourceforge.net/projects/mingw-w64/

安装好后添加环境变量

 检测

 3.安装插件

安装必要的插件,打开vscode,点击左面竖排第五个按钮,搜索并安装

  • C/C++
  • Code Runner

4.配置文件

新建文件夹(工作区)project

新建文件夹.vscode

新建文件launch.json,tasks.json

##launch.json 

注意修改mingw路径
{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe - 生成和调试活动文件",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "D:\mingw64\mingw64\bin\gdb.exe",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe build active file"
        }
    ]
}
##tasks.json 

{
    "tasks": [
        {
            "type": "shell",
            "label": "C/C++: g++.exe build active file",
            "command": "D:\mingw64\mingw64\bin\g++.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ],
    "version": "2.0.0"
}

4.1

新建文件,a.cpp

可以F5调试,也可以在终端g++,gdb调试

5.具体调试

内容见https://zhuanlan.zhihu.com/p/77645306

原文地址:https://www.cnblogs.com/lqerio/p/11688457.html