clion-debug调试步骤
clion-debug调试方法
脱坑神器
(先来一道水题,方便大家理解)
题目要求:
获取两个输入a,b,求a+b。
输入数据
:
0001 0002
输出结果
:
3
附上代码
:
#include <iostream>
#include <cstring>
using namespace std;
int string_to_int(string str){
//避免字符串是全0
if(str.find_first_not_of('0') == string::npos)return 0;
str = str.substr(str.find_first_not_of('0'));
int a;
sscanf(str.c_str(),"%d",&a);
return a;
}
int main(){
string str1,str2;
cin>>str1>>str2;
int a = string_to_int(str1);
int b = string_to_int(str2);
int c = a+b;
cout<<c;
return 0;
}
测试一波
:
操作细节:
debug步
:
1. 打断点
点击左侧会出现一个红点
由于clion比较智能,断点大致在那么范围就可以了。
2.点击debug
3.输入数据
4.下一条指令
clion同时会把对应的数值放在代码行的后面
继续点,就会到下一条指令去。
如果有循环可以点击左边框的箭头,到下一条指令去。
clion的debug用来代码查错很方便。