c++前處理器
阿新 • • 發佈:2020-12-26
#include <iostream> using namespace std; int main() { #define PI 3.1415 cout << PI << endl; #define DEBUG #ifdef DEBUG cerr << "Debug" << endl; #endif // DEBUG #if 0 //註釋功能; cout << "comment" << endl; #endif // 0 //#和##的使用:#將值變為變為字串,##連線兩個'值'為字串; #define MAKESTRING(x) #x cout << MAKESTRING(helloworld) << endl; #define CONCATSTRING(x, y) x ## y cout << CONCATSTRING(1, 2) << endl; //其他用法; cout << __LINE__<< endl; //列印當前行; cout << __FILE__ << endl; //列印當前檔案路徑; cout << __DATE__ << endl; //列印當前日期; cout << __TIME__ << endl; //列印當前時間; return 0; }