无需下载MinGw,在已有CodeBlocks的情况下,给VS code配置c++的极简方法

  • 下载c/c++插件
  • 新建一个文件夹,用code打开   

  •  建立.vscode文件夹(注意有个点),再建立以下4个文件

  • c_cpp_properties.json
  • launch.json
  • tasks.json
  • settings.json

 

  • 在4个文件夹里分别粘贴如下代码

 c_cpp_properties.json

{
    "configurations": [
        {
            "name": "GCC",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.22000.0",
            "compilerPath": "D:\\Software\\CodeBlocks\\MinGW\\bin\\g++.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-gcc-x64"
        }
    ],
    "version": 4
}

 launch.json

{
   "configurations": [
      {
         "name": "C/C++: g++.exe build and debug active file",
         "type": "cppdbg",
         "request": "launch",
         "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
         "args": [],
         "stopAtEntry": false,
         "cwd": "${fileDirname}",
         "environment": [],
         "externalConsole": true,
         "MIMode": "gdb",
         "miDebuggerPath": "D:\\Software\\CodeBlocks\\MinGW\\bin\\gdb.exe",
         "setupCommands": [
            {
               "description": "Enable pretty-printing for gdb",
               "text": "-enable-pretty-printing",
               "ignoreFailures": true
            },
            {
               "description": "Set Disassembly Flavor to Intel",
               "text": "-gdb-set disassembly-flavor intel",
               "ignoreFailures": true
            }
         ],
         "preLaunchTask": "C/C++: g++.exe build active file"
      }
   ],
   "version": "2.0.0"
}

tasks.json

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "D:\\Software\\CodeBlocks\\MinGW\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "D:\\Software\\CodeBlocks\\MinGW\\bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

settings.json

{
    "files.associations": {
        "*.cpp": "cpp",
        "ostream": "cpp",
        "iostream": "cpp"
    }
}
  • 最重要的一步

找到你Code Blocks安装文件夹的MinGW文件夹的bin文件夹,复制路径,并添加到环境变量,如下是我的

在c_cpp_properties.json,launch.json,tasks.json这3个文件里找到有路径的地方(可以搜索MinGW),替换成你的路径,一共有4处(应该是)

至此已经完成,注意要在与.vscode文件夹同目录建立cpp文件。之后每次开启新项目,要把.vscode文件夹复制到新项目的文件夹里。

碎碎念:之所以会用VSCode写C++,是因为它可以实现这样的功能——在文件夹里同时放很多有main函数的cpp文件,每次可以只运行选择的那个cpp文件(见下图)。这样刷题很方便。如果有其他实现类似功能的方法,也欢迎大家评论。

留个坑:过几天把VScode的代码自动格式化、利用GitHub备份、写markdown笔记以及利用markdown做PPT等等我的各种配置记录一下。

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值