#是字符串化的意思,出现在宏定义中的#是把跟在后面的参数转成一个字符串;
##是连接符号,把参数连接在一起。
例子:
#include <iostream>using namespace std;#define A(exp) cout << "I am "#exp << endl;#define B(exp) cout << sz##exp << endl;int main(){ const char *szStr = "test"; A(Chinese); // cout << "I am ""Chinese" << endl; B(Str); // cout << szStr << endl; return 0;}#include <iostream>using namespace std;#define OUTPUT(A) cout<<#A<<":"<<(A)<<endl;#define CONCAT(A,B) A##Bint main(){ int a=1,b=2; OUTPUT(a); //a:1 OUTPUT(b); //b:2 OUTPUT(a+b); //a+b:3 cout<<CONCAT(1,2); //12 return 0;}
新闻热点
疑难解答
图片精选