zoukankan      html  css  js  c++  java
  • 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 }

    运行结果


  • 相关阅读:
    希尔排序
    折半插入排序
    自学git心得-2
    读书笔记-1 《人月神话》
    USTCCourseCommunity 项目介绍
    自学git心得-1
    HDU 2006 求奇数的乘积
    HDU 2007 平方和与立方和
    HDU 2005 第几天?
    HDU 2004 成绩转换
  • 原文地址:https://www.cnblogs.com/CocoonFan/p/3117303.html
Copyright © 2011-2022 走看看