预定义符号常量

预定义符号常量

 

C++继承了ANSI C的预定义常量,预处理器在处理代码时将它们替换为确定的字面常量。这些符号不能用#define重新定义,也不能用#undef取消该宏。

__LINE__ 引用语句的代码行号
__FILE__ 引用语句所在的文件名
__DATE__ 引用语句所在源文件被编译的时期
__TIME__ 引用语句所在源文件被编译的时间

#include<iostream>
#include <fstream>
//#include "apue.h"
//#include <sys/wait.h>
//#define MAXLINE 2048 
using namespace std;

int
main (int argv, char** arg)
{
    cout<<__LINE__<<endl;
    cout<<__FILE__<<endl;
    cout<<__DATE__<<endl;
    cout<<__TIME__<<endl;
    return 0;
}

输出:

11
test.cpp
Feb 28 2009
21:12:59

你可能感兴趣的:(预定义符号常量)