Visual Studio Code 下载/配置 c++环境

Visual Studio Code 下载/配置 c++环境

1. vsCode下载

vscode官网下载

2. vsCode安装



这一步反正最后一项要选,其他看自己需要

确认无误安装即可

如果你看到如下界面,那么恭喜你,你的VSCode安装完成。

3. vsCode配置

3.1 插件下载

  • 必备插件
  1. Chinese(简体中文)——————安装完成后有右下角的提示框蓝色按钮按一下
  2. C/C++
  • 推荐插件
  1. Error Lens
  2. Markdown Preview Enhanced
  3. vscode-pdf

3.2 编译器下载

TDM-GCC或MinGW都可以
Mingw
TDM-GCC

3.3 编辑系统环境变量



把编译器bin的绝对路径添加进去

打开命令行输入 gcc -v 如果在末尾显示有版本好那恭喜你,你已经成功一半了!

3.4 配置vsCode调试

  1. 新建文件夹 vsCode
  2. vsCode 目录下创建两个文件夹 .vscodecode
  3. .vscode 目录下创建三个文件 c_cpp_properties.jsonlaunch.jsontasks.json,依次填充代码并根据注释更改地址

c_cpp_properties.json

{
    "configurations": [
        {
          "name": "Win32",
          "includePath": ["${workspaceFolder}/**"],
          "defines": ["_DEBUG", "UNICODE", "_UNICODE"],
          "windowsSdkVersion": "10.0.17763.0",
          "compilerPath": "F:\\mingw64\\bin\\g++.exe",  //将路径更改为自己编译器目录下bin文件夹里g++.exe
          "cStandard": "c11",
          "cppStandard": "c++17",
          "intelliSenseMode": "${default}"
        }
      ],
      "version": 4
}

launch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "F:\\mingw64\\bin\\gdb.exe",  //将路径更改为自己编译器目录下bin文件夹里gdb.exe
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "防止 gdb 打开标准库函数",
                    "text": "-interpreter-exec console \"skip -gfi **/bits/*.h\"",
                    "ignoreFailures": false
                }
            ],
            "symbolLoadInfo": {
                "loadAll": false,
                "exceptionList": ""
            },
            "preLaunchTask": "task g++"
        }
    ]
}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "task g++",
            "command": "F:\\mingw64\\bin\\g++.exe",  //将路径更改为自己编译器目录下bin文件夹里g++.exe
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "-I",
                "F:\\vsCode",
                "-std=c++17"
            ],
            "options": {
                "cwd": "F:\\mingw64\\bin"  //将路径更改为自己编译器目录下bin文件夹
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build"
        },
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe 生成活动文件",
            "command": "F:\\mingw64\\bin\\g++.exe",  //将路径更改为自己编译器目录下bin文件夹里g++.exe
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        }
    ]
}

程序放在 code 文件夹里,以后缀为.cpp存储
按下F5调试
至此,vsCode已完成c++环境配置

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值