define中#、##、#@分別表示什麼

1. # 字符串化, 例如:

#define  LogMessage(a)   printf("The message is: %s", #a);
 
LogMessage(WARNING)    //The message is:WARNING
 
string ppp="abcdef";
LogMessage(ppp)    //The message is: ppp; not "abcdef"

2. ## 符號連接操作,例如:

#define  Sum_Number(b)    Num##b
#define  Num9    999
 
Sum_Number(9)     //999


3. #@ 字符化,例如:

#define TEST(tp,charactor)  \
{  \
    char a[100]{0};\
    sprintf_s("%s,%c", #tp, #@charactor); \
    TRACE(a); \
}
 
TEST(WARNING,  C);  //輸出,WARNING, C

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章