配置vscode 的C/C++ 环境
1、首先下载mingw,以及vscode
2、添加mingw的环境变量
3、配置vscode文件
按 ctrl + shift + p , 输入configuration, 选择 edit configuration
{ "configurations": [{ "name": "Win32", "includePath": [ "${workspaceFolder}/**" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE" ], "compilerPath": "D:\\programme installation 2\\mingw\\mingw64\\bin\\g++.exe", "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "clang-x64" }], "version": 4 }
然后ctrl + shift + p, 输入task ,选择 default build task
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "type": "shell", "label": "g++.exe build active file", "command": "D:\\programme installation 2\\mingw\\mingw64\\bin\\g++.exe", "args": [ "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true } } ] }
最后按 ctrl + shift + p,输入launch,选择launch.json
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "preLaunchTask": "g++.exe build active file",//调试前执行的任务,就是之前配置的tasks.json中的label字段 "type": "cppdbg",//配置类型,只能为cppdbg "request": "launch",//请求配置类型,可以为launch(启动)或attach(附加) "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",//调试程序的路径名称 "args": [],//调试传递参数 "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true,//true显示外置的控制台窗口,false显示内置终端 "MIMode": "gdb", "miDebuggerPath": "D:\\programme installation 2\\mingw\\mingw64\\bin\\gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
以上的文件配置代码可以直接复制。
程序可以运行。