vscode怎么调试c语言
2024-03-28 03:19:01
1、打开你要写c++程序的文件夹,我们这里新建一个Test文件夹并打开test,打开后:使用VScode运行调试C/C++,在左侧打开的目录中新建一个 main.cpp 文件。
2、新建后点左侧的调试按钮(英文:Debug),可以看到,目前没有调试配置。
3、这时我们需要配置自己的调试配置,回到资源管理器界面,我们可以看到目录下多了一个.vscode的文件夹,里面有一个launch.json文件。我们现在在这个文件夹中新建一个tasks.json文件。我们需要改写这两个json文件的内容。
{
version: 0.2.0,
configurations: [
{
name: Run C/C++,
type: cppdbg,
request: launch,
program: ${workspaceFolder}/${fileBasenameNoExtension}.exe,
args: [],
stopAtEntry: false,
cwd: ${workspaceFolder},
environment: [],
externalConsole: true,
MIMode: gdb,
miDebuggerPath: C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/gdb.exe,
setupCommands: [
{
description: Enable pretty-printing for gdb,
text: -enable-pretty-printing,
ignoreFailures: false
}
],
preLaunchTask: build & run file
},
{
name: Debug C/C++,
type: cppdbg,
request: launch,
program: ${workspaceFolder}/${fileBasenameNoExtension}.exe,
args: [],
stopAtEntry: false,
cwd: ${workspaceFolder},
environment: [],
externalConsole: true,
MIMode: gdb,
miDebuggerPath: C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/gdb.exe,
setupCommands: [
{
description: Enable pretty-printing for gdb,
text: -enable-pretty-printing,
ignoreFailures: false
}
],
preLaunchTask: build & debug file
}
]
}
其中tasks.json文件内容(直接复制即可):
{
version: 2.0.0,
tasks: [
{
label: build & debug file,
type: shell,
command: g++,
args: [
-g,
-o,
${fileBasenameNoExtension},
${file}
],
group: {
kind: build,
isDefault: true
}
},
{
label: build & run file,
type: shell,
command: g++,
args: [
-o,
${fileBasenameNoExtension},
${file}
],
group: {
kind: build,
isDefault: true
}
}
]
}
4、我们已经完成了基本的配置工作,保存以上两个json文件后,再次点击左侧的调试按钮(Debug),可以发现出现了两个新的配置,一个是直接运行程序的Run,一个是用来调试程序的Debug。
5、我们写一个简单的c++程序来进行调试说明,程序源代码,我们在return 0这行添加了一个断点。
6、切换运行配置为Debug C/C++,点击运行按钮开始调试。
7、可以看到,弹出的终端输出了正确的结果,调试窗口中的变量中也有变量a和对应的值。
声明:本网站信息来自网络,所有数据仅供参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:abc5566@foxmail.com。
- 上一篇:智学网怎么绑定学生账号
- 下一篇:三面玻璃的阳台地台怎么做
猜你喜欢
-
最经典的上海本帮菜前十
阅读量:66 -
云南小吃排行榜
阅读量:16 -
云南有哪些特色美食
阅读量:76 -
北京人早餐吃什么
阅读量:8 -
河北美食排行榜
阅读量:88 -
云南特色小吃有哪些
阅读量:28 -
天津最好吃的美食街
阅读量:95 -
天津五大著名小吃街
阅读量:55 -
西安最好吃的羊肉泡馍在哪
阅读量:93 -
吉林老字号美食推荐
阅读量:71
-
阅读量:27
-
阅读量:38
-
阅读量:6
-
阅读量:83
-
阅读量:26
-
阅读量:23
-
阅读量:55
-
阅读量:74
-
阅读量:69
-
阅读量:51