# 字符串化運算符在宏定義中,#參數 將實參轉換為字符串字面量(自動加雙引號、轉義)。
##標記粘合運算符在宏定義中,
前綴##後綴將兩個標記合併為一個標記(無空格)。#define LOG(var) std::cout << #var " = " << var << std::endl; int x = 42; LOG(x); // std::cout << "x" << " = " << x << std::endl; #define DECL_ARRAY(name, size) int name##_arr[size]; DECL_ARRAY(buf, 1024); // int buf_arr[1024];注意事項
## 不能出現在宏定義的首尾。# 和 ## 可嵌套使用,但需注意展開順序(參數先完全展開,再應用 #/##)。