VsCode环境搭建(踩在巨人的肩膀上)

1.VS code安装和C++环境搭建

前面这个是搭建简单环境的,没办法进行复杂运算的,而下面这个是比较完善的,防止跑偏了。

2.VS Code安装和C/C++环境搭建2

3.安装综合

报错的解决方案

4.g++报错

5.命令行界面闪退闪现及断点调试失效

如果以上内容能帮到您请给这些大佬点赞,大家都不容易。

现在我分享一下我的环境(几个文件都是.json)

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.17763.0",
            "compilerPath": "D:\\Users\\mingw64\\bin\\g++.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "${default}"
        },
        {
            "name": "Win64",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "D:\\Users\\mingw64\\bin\\gcc.exe",
            "cStandard": "gnu17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-gcc-x64",
            "mergeConfigurations": false,
            "browse": {
                "path": [
                    "${workspaceFolder}/**"
                ],
                "limitSymbolsToIncludedHeaders": true
            }
        }
    ],
    "version": 4
}

launch.json

{
  "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": "D:\\Users\\mingw64\\bin\\gdb.exe",
      "setupCommands": [
        {
          "description": "为 gdb 启用整齐打印",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ],
      "preLaunchTask": "task g++"
    },
    {
      "name": "C/C++: g++.exe 生成和调试活动文件",
      "type": "cppdbg",
      "request": "launch",
      "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${fileDirname}",
      "environment": [],
      "externalConsole": false,
      "MIMode": "gdb",
      "miDebuggerPath": "D:\\Users\\mingw64\\bin\\gdb.exe",
      "setupCommands": [
        {
          "description": "为 gdb 启用整齐打印",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        },
        {
          "description": "将反汇编风格设置为 Intel",
          "text": "-gdb-set disassembly-flavor intel",
          "ignoreFailures": true
        }
      ],
      "preLaunchTask": "C/C++: g++.exe 生成活动文件"
    },
    {
      "name": "(Windows) Launch",
      "type": "cppvsdbg",
      "request": "launch",
      "program": "cmd",
      "preLaunchTask": "echo",
      "args": [
          "/C",
          "${fileDirname}\\${fileBasenameNoExtension}.exe",
          "&",
          "echo.",
          "&",
          "pause"
      ],
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}",
      "environment": [],
      "externalConsole": true
  },
  {
      "name": "(gdb) Launch",
      "type": "cppdbg",
      "request": "launch",
      "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}",
      "environment": [],
      "externalConsole": true,
      "MIMode": "gdb",
      "miDebuggerPath": "D:\\Users\\mingw64\\bin\\gdb.exe", // 自己电脑的gdb
      "preLaunchTask": "echo", //这里和task.json的label相对应
      "setupCommands": [
          {
              "description": "Enable pretty-printing for gdb",
              "text": "-enable-pretty-printing",
              "ignoreFailures": true
          }
      ]
  }
  ]
}

settings.json

{
  "run.inputFile": "${workspaceFolder}",
  "cmake.sourceDirectory": "${workspaceFolder}/vscode_project/",
  "cmake.configureOnOpen": true,
  "files.autoSave": "afterDelay",
  "terminal.integrated.defaultProfile.windows": "Command Prompt",
  "C_Cpp.errorSquiggles": "disabled"
}

tasks.json

{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "shell",
      "label": "task g++",
      "command": "D:\\Users\\mingw64\\bin\\g++.exe",
      "args": [
        "-g",
        "${file}",
        "-o",
        "${fileDirname}\\${fileBasenameNoExtension}.exe",
        "-std=c++11"
      ],
      "options": {
        "cwd": "D:\\Users\\mingw64\\bin"
      },
      "problemMatcher": [
        "$gcc"
      ],
      "group": {
        "Kind": "build",
        "isDefault": true
      }
    },
    {
      "type": "cppbuild",
      "label": "C/C++: cpp.exe 生成活动文件",
      "command": "D:\\Users\\mingw64\\bin\\cpp.exe",
      "args": [
        "-fdiagnostics-color=always",
        "-g",
        "${file}",
        "-o",
        "${fileDirname}\\${fileBasenameNoExtension}.exe"
      ],
      "options": {
        "cwd": "${fileDirname}"
      },
      "problemMatcher": [
        "$gcc"
      ],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "detail": "调试器生成的任务。"
    },
    {
      "type": "cppbuild",
      "label": "C/C++: g++.exe 生成活动文件",
      "command": "D:\\Users\\mingw64\\bin\\g++.exe",
      "args": [
        "-fdiagnostics-color=always",
        "-g",
        "${file}",
        "-o",
        "${fileDirname}\\${fileBasenameNoExtension}.exe"
      ],
      "options": {
        "cwd": "${fileDirname}"
      },
      "problemMatcher": [
        "$gcc"
      ],
      "group": "build",
      "detail": "调试器生成的任务。"
    },

    {
      "label": "echo",
      "type": "shell",
      "command": "gcc",
      "args": [
          "-g",
          "${file}",
          "-o",
          "${fileBasenameNoExtension}.exe",
          "-fexec-charset=GBK" //解决中文乱码
      ]
  }
  ],
  "presentation": {
    "echo": true,
    "reveal": "always",
    "focus": false,
    "panel": "shared",
    "showReuseMessage": true,
    "clear": false
}
}

 全部弄好就是这样

PS:一定要先看前面大佬的经验,不然,一直会有问题报错

我的也有点小问题

继续看大佬的建议

改用”console"

关于VScode报错“终端将被任务重用,按任意键关闭”的解决方案

如果以上都无法帮助你,那就只有官方了

C\C++插件的官方使用教程

如果您觉得这篇文章对您有帮助的话请点个赞,谢谢

补充1:VSCode 最全实用插件(VIP典藏版)

补充2:踩过的坑

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值