#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
#include <stdio.h>
//#用来把参数名转换成字符串
#define P(x) printf("%s=%d\n",#x,x); //打印变量名及值。
#define SQUARE(x) printf("The square of "#x" is %d.\n", ((x)*(x))); //x的平方
//##拼接变量名或函数名等。可以像函数指针一样fun##x()
#define RNAME(x) a##x
//__VA_ARGS__可变参数,即编译时 替换...,##当可变参数的个数为0时,这里的##起到把前面多余的","去掉的作用,否则会编译出错
#define log_printf(fmt,...) printf("[%s|%d]"fmt"\n",__func__,__LINE__,##__VA_ARGS__)
//可变参数输出到终端和追加到文件等
#define logf_printf(fmt,...) do { char temp[1024]={0}; sprintf(temp,"[%s|%d]"fmt"\n",__func__,__LINE__,##__VA_ARGS__); printf(temp);\
std::ofstream outfile; outfile.open("log.txt", std::ios::out | std::ios::app); outfile << std::string(temp); outfile.close(); }while(0)
void main()
{
int a3=8;
P(a3);
SQUARE(8);
log_printf("Test%d", RNAME(3));
logf_printf("%d",880999);
system("pause");
}