CodeBlocks调试功能快捷教程

来源:互联网 发布:2016新鲜网络赚钱项目 编辑:程序博客网 时间:2024/05/21 22:29

  在程序设计中,单步调试能够跟踪程序的执行流程。跟踪过程中,还可以观察变量的变化,从而发现其中存在的问题。单步执行除了可以帮助我们发现设计的程序中存在的问题,对于初学者,还可以帮助我们理解语言的机制。

  所以,对于初学者,掌握所用的集成开发环境的一般用法,是一件非常重要的事情。

  由于其重要性,再引用中国的一句古话“工欲善其事,必先利其器”,单步调试就是程序设计者最重要的工具之一,这种工具的形态是软件。程序员用软件当工具,正常得不得了。

  本文介绍CodeBlock的调试功能。因为面向初学者,高手请绕行。到资源中下载,请点链接:http://download.csdn.net/detail/sxhelijian/6541685

  (相关链接——我写的VC++中调试功能:VC++6.0调试工具使用初步)








示例代码:
[cpp] view plain copy
 print?
  1. #include <iostream>  
  2. using namespace std;  
  3. const double pi=3.1415926;  
  4. int main( )  
  5. {  
  6.     float r,a;  
  7.     cout<<"输入半径:"<<endl;  
  8.     cin>>r;  
  9.     a=pi*r*r;  
  10.     cout<<"输出面积:";  
  11.     cout<<a<<endl;  
  12.     return 0;  
  13. }  
  14.   
  15. float volume(float h,float r)  
  16. {  
  17.     return pi*r*r*h;  
  18. }  






实践代码:

[cpp] view plain copy
 print?
  1. #include <iostream>  
  2. using namespace std;  
  3. const double pi=3.1415926;  
  4. int main( )  
  5. {  
  6.     int a;  
  7.     cout<<"请输入一个数:"<<endl;  
  8.     cin>>a;  
  9.     if(a = 2)  
  10.         cout<<"你2了。";  
  11.     else  
  12.         cout<<"你不2。";  
  13.     return 0;  
  14. }  






示例代码:
[cpp] view plain copy
 print?
  1. #include <iostream>  
  2. using namespace std;  
  3. const double pi=3.1415926;  
  4. float area(float r);  
  5. int main( )  
  6. {  
  7.     float r1,a1;  
  8.     cin>>r1;  
  9.     a1=area(r1);  
  10.     cout<<a1<<endl;  
  11.     return 0;  
  12. }  
  13. float area(float r)  
  14. {  
  15.     float a;  
  16.     a = pi*r*r;  
  17.     return a;  
  18. }  





实践代码:
[cpp] view plain copy
 print?
  1. #include <iostream>  
  2. using namespace std;  
  3. float max(float x, float y);  
  4. int main ()  
  5. {  
  6.     float a,b,c;  
  7.     cin>>a>>b;  
  8.     c=max(a, b) ;  
  9.     cout<<"The max is "<<c<<endl;  
  10.     return 0;  
  11. }  
  12. float max(float x, float y)  
  13. {  
  14.     float z;  
  15.     z=(x<y)? x : y ;  
  16.     return  z;  
  17. }  




示例代码:

[cpp] view plain copy
 print?
  1. #include<iostream>  
  2. #include<cmath>  
  3. using namespace std;  
  4. int max(int,int);  
  5. int main( )  
  6. {  
  7.     int m,a,b;  
  8.     a=100;  
  9.     b=200;  
  10.     m=max(a,b);  
  11.     cout<<"最大:"<<m<<endl;  
  12.     return 0;  
  13. }  
  14. int max(int x,int y)  
  15. {  
  16.     int z;  
  17.     if(x>y)  
  18.         z=x;  
  19.     else  
  20.         z=y;  
  21.     return z;  
  22. }  




实践代码:
[cpp] view plain copy
 print?
  1. #include <iostream>  
  2. using namespace std;  
  3. float max(float x, float y);  
  4. int main ()  
  5. {  
  6.     float a,b,c;  
  7.     cin>>a>>b;  
  8.     c=max(a, b) ;  
  9.     cout<<"The max is "<<c<<endl;  
  10.     return 0;  
  11. }  
  12. float max(float x, float y)  
  13. {  
  14.     float z;  
  15.     z=(x<y)? x : y ;  
  16.     return  z;  
  17. }  




CodeBlocks调试功能快捷教程   


0 0