C/C++ 程序调试的几个小技巧

C/C++ 程序调试的几个小技巧

直接看代码


 

 1 #include <iostream>
 2 #include <cassert>
 3 #include <cstdlib>
 4 
 5 /* 常用debug 方法
 6  *  1、cout.....
 7  *  2、#ifndef NDEBUG
 8  *        // debug infomation
 9  *     #endif
10  *  3、assert()断言
11  */
12 
13 
14 //#define NDEBUG 
15 //或者使用g++ -DNODEBUG fileName.cpp 命令去掉debug信息
16 
17 using namespace std;
18 
19 int main()
20 {
21 
22     #ifndef NDEBUG
23         cerr << "Error File: " << __FILE__ << endl;
24         cerr << "Error Line: " << __LINE__ << endl;
25         cerr << "Error Date: " << __DATE__ << endl;
26         cerr << "Error Time: " << __TIME__ << endl;
27     #endif
28     
29     int i;
30     cin >> i;
31     
32     //常用assert来测试不可能发生的错误,不应使用它来替换程序逻辑
33     //这里为了方便看出结果给出一个可能的错误
34     assert(i == 0);
35 
36     system("pause");
37 
38     return 0;
39 }

 

运行结果


 

转载于:https://www.cnblogs.com/CocoonFan/archive/2013/06/04/3117303.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值