如何在宏字符串中嵌入一个整数?
How to embed an integer in a macro string?
我第一次看到字符串化和标记粘贴。我觉得它可能是这个宏的好工具:
#define MY_NUMBER 3
#define MY_STRING "the number three: ##MY_NUMBER"
printf("%s\n", MY_STRING);
应该输出:
the number three: 3
试试这个
#define S_(x) #x
#define S(x) S_(x)
#define MY_NUMBER 3
#define MY_STRING "the number three: " S(MY_NUMBER)
我第一次看到字符串化和标记粘贴。我觉得它可能是这个宏的好工具:
#define MY_NUMBER 3
#define MY_STRING "the number three: ##MY_NUMBER"
printf("%s\n", MY_STRING);
应该输出:
the number three: 3
试试这个
#define S_(x) #x
#define S(x) S_(x)
#define MY_NUMBER 3
#define MY_STRING "the number three: " S(MY_NUMBER)