配置vscode的C/C++环境

一、下载g++

官网:News - nuwen.net

解压下载的文件

二、配置环境变量

进入g++的bin文件复制路径

win+r打开运行对话框

输入 sysdm.cpl 打开系统属性

点击高级

点击环境变量

双击用户变量里的path

新建

把复制的bin文件地址复制进去

再点三个确定

三、安装插件

在扩展中搜索并下载

下载图中的插件

四、调式配置

在自己想要的任意位置创建一个文件夹

比如在D盘创建一个 vscode_c_file文件夹

在创建的 vscode_c_file 文件夹里面创建文件夹

.vscode    (一定要创建)

其他文件夹根据实际情况创建

在 .vscode文件夹里面创建四个文件(注意文件后缀)

可以在vscode中右键.vscode文件夹进行创建

c_cpp_properties.json

launch.json

settings.json

tasks.json

然后找到g++.exe文件地址

可以在终端使用 where g++找到

四个文件内容如下:

首先是c_cpp_properties.json

其中compilerPath这一项要把路径改成刚才g++的安装路径:找到刚刚的安装文件夹D:\gcc_release\mingw64\bin\g++.exe,然后复制或者手动把g++.exe的路径敲上去,格式要跟上面代码段一样

{
  "configurations": [
    {
      "name": "Win64",
      "includePath": ["${workspaceFolder}/**"],
      "defines": ["_DEBUG", "UNICODE", "_UNICODE"],
      "windowsSdkVersion": "10.0.18362.0",
      "compilerPath": "C:/MinGW/bin/g++.exe",
      "cStandard": "c17",
      "cppStandard": "c++17",
      "intelliSenseMode": "gcc-x64"
    }
  ],
  "version": 4
}

然后是launch.json

注意miDebuggerPath这一项也要把路径改成刚才g++的安装路径:找到刚刚的安装文件夹D:\gcc_release\mingw64\bin\g++.exe ,然后复制或者手动把gdb.exe的路径敲上去,格式要跟上面代码段一样

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "(gdb) Launch", 
      "type": "cppdbg", 
      "request": "launch", 
      "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", 
      "args": [], 
      "stopAtEntry": false,
      "cwd": "${workspaceRoot}",
      "environment": [],
      "externalConsole": true, 
      "MIMode": "gdb",
      "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
      "preLaunchTask": "g++",
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ]
    }
  ]
}

然后是settings.json

{
    "files.associations": {
      "*.py": "python",
      "iostream": "cpp",
      "*.tcc": "cpp",
      "string": "cpp",
      "unordered_map": "cpp",
      "vector": "cpp",
      "ostream": "cpp",
      "new": "cpp",
      "typeinfo": "cpp",
      "deque": "cpp",
      "initializer_list": "cpp",
      "iosfwd": "cpp",
      "fstream": "cpp",
      "sstream": "cpp",
      "map": "c",
      "stdio.h": "c",
      "algorithm": "cpp",
      "atomic": "cpp",
      "bit": "cpp",
      "cctype": "cpp",
      "clocale": "cpp",
      "cmath": "cpp",
      "compare": "cpp",
      "concepts": "cpp",
      "cstddef": "cpp",
      "cstdint": "cpp",
      "cstdio": "cpp",
      "cstdlib": "cpp",
      "cstring": "cpp",
      "ctime": "cpp",
      "cwchar": "cpp",
      "exception": "cpp",
      "ios": "cpp",
      "istream": "cpp",
      "iterator": "cpp",
      "limits": "cpp",
      "memory": "cpp",
      "random": "cpp",
      "set": "cpp",
      "stack": "cpp",
      "stdexcept": "cpp",
      "streambuf": "cpp",
      "system_error": "cpp",
      "tuple": "cpp",
      "type_traits": "cpp",
      "utility": "cpp",
      "xfacet": "cpp",
      "xiosbase": "cpp",
      "xlocale": "cpp",
      "xlocinfo": "cpp",
      "xlocnum": "cpp",
      "xmemory": "cpp",
      "xstddef": "cpp",
      "xstring": "cpp",
      "xtr1common": "cpp",
      "xtree": "cpp",
      "xutility": "cpp",
      "stdlib.h": "c",
      "string.h": "c"
    },
    "editor.suggest.snippetsPreventQuickSuggestions": false,
    "aiXcoder.showTrayIcon": true
  }

最后是tasks.json

{
    "version": "2.0.0",
    "tasks": [
      {
        "label": "g++",
        "command": "g++",
        "args": [
          "-g",
          "${file}",
          "-o",
          "${fileDirname}/${fileBasenameNoExtension}.exe"
        ],
        "problemMatcher": {
          "owner": "cpp",
          "fileLocation": ["relative", "${workspaceRoot}"],
          "pattern": {
            "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "message": 5
          }
        },
        "group": {
          "kind": "build",
          "isDefault": true
        }
      }
    ]
  }

四个文件配置完成

以后的c/c++文件必须放在有 .vscode 文件夹的文件夹里面才能调试否则报错

五、解决无法在只读编辑器编辑

点击vscode左下角的齿轮

点击设置

搜索框输入 interminal

勾选 Run In Terminal 即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值