通用单步调试指南
单步调试是调试程序十分有用的方法,你可以逐行执行程序并查看变量的值。然而这一高效的方法并非在每个学校的编程课上都会教学。尤其是对于非计算机专业的学生,单步调试更可能闻所未闻,大大增加了调试程序的难度。本文旨在大致介绍单步调试所包含的内容和操作方法。
一些提示与准备提示:在本文中提到的开发环境一词可以理解为你编程使用的软件
在某些开发环境(如CodeBlock)下,尽管你可以在不创建项目的情况下编译代码,但是你仍然需要创建项目才能使用调试工具。
在大多数开发环境下,你可以点击最上方的调试 (Debug)选项卡(可能会是不同的名字)上看到本文接下来会提到的操作对应的按键。熟练掌握快捷键会大幅度提高操作的效率。
图中从左向右分别展示了Visual Studio 2019, Visual Studio Code 与 Codeblock的菜单
单步调试的操作在绝大多数的开发环境下都大同小异,且与使用的编程语言无关。因此本指南使用Visual Studio 2019开发环境,C++语言作为演示。
断点 (Breakpoint)顾名思义,断点可以理解为是一个可以打在代码某一行上的点。在 ...