MFC 數據類型轉換(int/CString,CString/char*,LPTSTR/char*,LPTSTR/CString)

1,int / CString互轉

int 轉 CString :

int s = 123; 

CString str;

str.Format(_T("%d"),s); 

////////////////////

CString 轉 int :

CString strl ;

int  nIndex = _ttoi(str);

 

2,char *(或const char *) 轉 Cstring

char *s = "char *";

CString str;

str.Format(_T("%s"),s); 

 

3,const char * 轉 LPTSTR(LPCTSTR) 

LPTSTR lptStr=new TCHAR[32];

TCHAR* szBuf=_T("Hello");

以上兩個語句,無論是在ANSI編碼方式,還是在Unicode編碼方式下都是正確的。

 

4,CString 轉  LPTSTR(LPCTSTR)

CString path1;

LPTSTR path2=path1.GetBuffer(path1.GetLenght());

 

//continue..

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