CodeBlocks調試功能快捷教程


在程序設計中,單步調試能夠跟蹤程序的執行流程。跟蹤過程中,還可以觀察變量的變化,從而發現其中存在的問題。單步執行除了可以幫助我們發現設計的程序中存在的問題,對於初學者,還可以幫助我們理解語言的機制。

  所以,對於初學者,掌握所用的集成開發環境的一般用法,是一件非常重要的事情。

  由於其重要性,再引用中國的一句古話“工欲善其事,必先利其器”,單步調試就是程序設計者最重要的工具之一,這種工具的形態是軟件。程序員用軟件當工具,正常得不得了。

  本文介紹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. }  

 



 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM