_FILE_和_LINE_在确认调试输出的来源方面很有作用;_DATE_和_TIME_常常用于在被编译的程序中加入版本信息
#include<stdio.h>
#include<Windows.h>
#define PRINT \
printf("%s,%d,%s,%s\n",__FILE__,__LINE__,__DATE__,__TIME__)
int main()
{
PRINT;
system("pause");
return 0;
}
将一个宏参数转换为一个字符串,不进行宏替换
#include<stdio.h>
#include<Windows.h>
#define PRINT(a,b) printf(" "#b"= "a"\n",b)
int main()
{
int x=20;
PRINT("%d",x+3);
system("pause");
return 0;
}
把位于他两边的符号连接成一个符号
#include<stdio.h>
#include<Windows.h>
#define STR1 "hello"
#define STR2 "world"
#define STR1STR2 "welcome to you"
#define CAT(a,b) a##b
int main()
{
printf("%s\n",CAT(STR1,STR2));
system("pause");
return 0;
}