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