CString strName;ide
char * pcName;spa
char cName[20];//1個字節,-128 到 127 或者 0 到 255code
unsigned short sName;orm
ACHAR * paName;unicode
TCHAR*ptName;string
wchar_t *pwName;//2 或 4 個字節,一個寬字節:typedef wchar_t short int;class
double dName;//8字節,+/- 1.7e +/- 308 (~15 個數字)co
int nName;//4字節,-2147483648 到 2147483647數字
std::wstring wsName;background
std::string ssName;
LPCTSTR 可當作CString 處理
LPCTSTR判空
LPCTSTR lpName; if (lpName!= NULL && lpName[0] != _T('\0')) { //不爲空; }
(1)CString轉unsigned short:
CString strName; unsigned short sName; sName = _ttoi(strNAme);
(2)CString轉化char[20]
(3)CString轉TCHAR*
CString strName; TCHAR*ptName; ptName = strName.GetBuffer();
(4)char[20]轉化ACHAR*
char cName[20]; ACHAR * paName; paName = _T("cName");
若以上操做無論用就定義一個CString,經過CString做爲中間量轉化
char cName[20]; CString strName; strName = cName; ACHAR * paName; paName = strName.GetBuffer();
(5)CString轉化double、long
CString strName; double dName; dName = _tstof(strName);
CString strName; long lName; lName = _ttol(strName);
(6)CString轉化int
CString strName; int nName; nName = _ttoi(strName);
(7)int轉CString
int nName; CString strName; strName. Format(_T("%d"), nName);
(8)std::wstring轉CString
std::wstring wsName; CString strName; strName = wsName.c_str();
(9)CString轉std::wstring
CString strName; std::wstring wsName; wsName = strName. GetString();
(10)std::string轉CString
std::string ssName; CString strName; strName = ssName.c_str();
(11)CString轉std::string
CString strName; CStringA stra( strName .GetBuffer(0)); std::string ssName(stra.GetBuffer(0)); stra.ReleaseBuffer();
unicode時,先轉爲非unicode. :
CString strName; std::string sstrConn; sstrConn = CT2A(strConn.GetBuffer());
(12) std::string 轉化Char*
std::string ssName; char * pcName = new char(20); pcName = ssName.data(); pcName = ssName.c_str();
(13) CString轉wchar_t *
CString strName; wchar_t *pwName; pwName = strName.AllocSysString();
(14) wchar_t * 轉 char *
wchar_t* pwName= NULL; MdStrToWCharPtr(pwName, strPathName); int iSize = WideCharToMultiByte(CP_ACP, 0, pwName, -1, NULL, 0, NULL, NULL); char *pcName = (char*)malloc(iSize*sizeof(char)); WideCharToMultiByte(CP_ACP, 0, pwName, -1, pcName , iSize, NULL, NULL);