宏定义中#的功能
C/C++宏定义#中的功能是将其后面的宏参数进行字符串化操作,简单说就是在对它所引用的宏变量通过替换后在其左右各添加一个双引号。
宏定义中##的功能
宏定义中##中的功能是在带参数的宏定义中将##前后的子串进行拼接。
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| #include <iostream> #include <climits>
using namespace std;
#define STR(s) #s #define CONS(a, b) int(a##e##b)
int main() { cout << STR(hello) << endl; cout << CONS(2, 3) << endl; return 0; }
hello 2000
|