#是字符串化的意思,出現(xiàn)在宏定義中的#是把跟在后面的參數(shù)轉(zhuǎn)成一個(gè)字符串;
##是連接符號(hào),把參數(shù)連接在一起。
例子:
#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;}
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注