首页  

C C++ 宏定义 # 与 ##     所属分类 c 浏览量 627
##   在带参数的宏定义中将两个子串(token)联接起来,从而形成一个新的子串
#    把参数当成字符串替代

#define TEST0(n) printf( "token" #n " = %d", token##n )

int token9 = 9;
TEST0(9);
printf( "token" "9" " = %d", token9 );
输出 token9=9



#include "iostream" #include "stdio.h" #define TEST0(n) printf( "token" #n " = %d \n", token##n ) #define TEST1(id) (std::cout << param##id << std::endl) #define TEST2(p) (std::cout << #p << std::endl) int main(){ int token9 = 9; // TEST0(9); int param1 = 1; int param2 = 2; // 1 TEST1(1); // 2 TEST1(2); // hello TEST2(hello); // "hello" TEST2("hello"); return 0; }

上一篇     下一篇
Linux Shell 多个命令中的分号(;) && ||

Linux echo输出彩色字符串

C/C++预编译指令

预定义宏 __cplusplus

c/c++标准预定义宏

c++ 结构体例子