|
CString strName;
char * pcName;
char cName[20];//1个字节,-128 到 127 或者 0 到 255
unsigned short sName;
ACHAR * paName;
TCHAR*ptName;
wchar_t *pwName;//2 或 4 个字节,一个宽字节:typedef wchar_t short int;
double dName;//8字节,+/- 1.7e +/- 308 (~15 个数字)
int nName;//4字节,-2147483648 到 2147483647
std::wstring wsName;
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)double转化CString
CString strName;
double dName;
strName.Format(_T("%f"), dName);
//如果想要去掉无效的0
strName.TrimRight(_T('0'));
strName.TrimRight(_T('.'));
(7)CString转化int
CString strName;
int nName;
nName = _ttoi(strName);
(8)int转CString
int nName;
CString strName;
strName. Format(_T("%d"), nName);
(9)std::wstring转CString
std::wstring wsName;
CString strName;
strName = wsName.c_str();
(10)CString转std::wstring
CString strName;
std::wstring wsName;
wsName = strName. GetString();
(11)std::string转CString
std::string ssName;
CString strName;
strName = ssName.c_str();
(12)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());
(13) std::string 转化Char*
std::string ssName;
char * pcName = new char(20);
pcName = ssName.data();
pcName = ssName.c_str();
(14) CString转wchar_t *
CString strName;
wchar_t *pwName;
pwName = strName.AllocSysString();
(15) 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); |
|