c++ 预处理的应用

//
//  main.cpp
//  test
//
//  Created by YaguangZhu on 15/6/25.
//  Copyright (c) 2015年 YaguangZhu. All rights reserved.
//

#include <stdio.h>
#include "stdlib.h"
#define DEBUG

int main()
{
    int i=0;
    char c;
    while (1) {
        i++;
        c= getchar();
        if (c !='\n') {
            getchar();
            
        }
        if (c =='q'||c=='Q') {
#ifdef DEBUG
            printf("we got:%c,about to exit.\n",c);
#endif
            break;
        }else
        {
            printf("i = %d",i);
#ifdef DEBUG
            printf(", we got :%c",c);
#endif
            printf("\n");
        }
    }
    return 0;
    
    
}
1
i = 1, we got :1
2
i = 2, we got :2
a
i = 3, we got :a
q
we got:q,about to exit.

如果注释第四行,debug没有被定义,那么#ifdef #endif 之间的消息将不会被输出

posted @ 2015-08-13 16:50  微博和csdn还有你  阅读(171)  评论(0编辑  收藏  举报