__FILE__
, __FUNCTION__
, __LINE__
主要是用來logging和debugging的.
帶#條件編譯的文章:
C++條件編譯(#define等)
舉例:
#include<iostream>
#include <stdio.h>
#define __DEBUG__
#ifdef __DEBUG__
#define DEBUG(format,...) printf("File: "__FILE__", Line: %05d: "format"\n", __LINE__, ##__VA_ARGS__)
#else
#define DEBUG(format,...)
#endif
int main() {
char str[]="Hello World";
DEBUG("A ha, check me: %s",str);
return 0;
}
輸出:
File: test.cpp, Line: 00011: A ha, check me: Hello World
參考資料:
__FILE__,__LINE__
What are__FILE__, __LINE__, and __FUNCTION__in C++