内容纲要

在插件里安装C/C++ for Visual Studio Code

在网上下载安装MinGW,安装必要的组件

在系统环境变量path里加入MinGW的bin目录

在VS code里打开一个文件夹,在文件夹下编写一个c/cpp文件,F5调试选择C/C++(GDB),将弹出的lauch.json内容换为

{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 “version”: “0.2.0”, “configurations”: [ { “name”: “(gdb) Launch”, “type”: “cppdbg”, “request”: “launch”, “program”: “${file}.exe”, “args”: [], “stopAtEntry”: false, “cwd”: “${workspaceFolder}”, “environment”: [], “externalConsole”: true, “MIMode”: “gdb”, “miDebuggerPath”: “C:\\MinGW\\bin\\gdb.exe”, “setupCommands”: [ { “description”: “Enable pretty-printing for gdb”, “text”: “-enable-pretty-printing”, “ignoreFailures”: true } ], “preLaunchTask”: “gcc”, } ]}

然后重新回到C/Cpp文件,再次F5调试,选择编写任务,然后选择Others模板,将生成的tasks.json内容替换如下:

{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format “version”: “2.0.0”, “command”: “gcc”, “args”: [“-g”, “${file}”, “-o”, “${file}.exe”,”-fexec-charset=GBK”], “problemMatcher”: { “owner”: “cpp”, “fileLocation”: [“relative”, “${workspaceRoot}”], “pattern”: { “regexp”: “^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$”, “file”: 1, “line”: 2, “column”: 3, “severity”: 4, “message”: 5 } }}

完成。

接下来这个文件夹下的C/Cpp程序都可以直接F5调试了。

Leave a Reply

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据