1._T("Hello")是一個宏,作用是讓程式支援Unicode編碼。
2.windows使用兩種字元集ANSI和UNICODE,前者使用的單位元組格式,後者使用雙位元組格式。
3.簡單一點講:
_T("hello world")表示:
在ansi的環境下,它是ansi的;
在unicode下,那麼它将自動解釋為雙位元組字元串,既unicode編碼。
好處:不管是ansi環境,還是unicode環境,都适用。
4.相當于:
#ifdef _UNICODE
#define _T("ABC") L"ABC" //每個字元16位
#else
#define _T("ABC") "ABC" //每個字元8位
#endif
5.舉例說明:
(1)#define Conn(x,y) x##y //表示:x連接配接y;
int n = Conn(123,456); // 結果就是n=123456;
char* str = Conn("asdf", "adf") //結果就是 str = "asdfadf";
(2)#define ToChar(x) #@x //表示:給x加上'',結果傳回是一個const char
char a = ToChar(1); //結果就是a='1';
越界試驗char a = ToChar(123); //結果是a='3';
如果你的參數超過四個字元,編譯器就報錯!error C2015: too many characters in constant :P
(3)#define ToString(x) #x //表示:給x加上""
char* str = ToString(123132); //就成了str="123132";
本文轉自 韬光星夜 51CTO部落格,原文連結:http://blog.51cto.com/xfqxj/498197,如需轉載請自行聯系原作者