首页 > 编程语言 > 详细

c++ 预处理的应用

时间:2015-08-13 17:20:13      阅读:156      评论:0      收藏:0      [点我收藏+]
//
//  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 之间的消息将不会被输出

c++ 预处理的应用

原文:http://www.cnblogs.com/zhuyaguang/p/4727781.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!