字符变量:
1. Char
2. Char*
3. CString
4. BSTR
数值变量
1. float
2. double
3. long
4. int
UNICODE 环境:
********************************************************************************************************
*******************字符与字符转换*******************
********************************************************************************************************
CString ----> BSTR
CString Str = L"str ";
BSTR bstr=Str.AllocSysString();
BSTR ----> CString
BSTR bstr = ::SysAllocString(L"str ");
CString Str = bstr;
WCHAR* ----> CString
_TCHAR* pWstr="str";
CString str=pWstr;
CString ----> WCHAR*
CString Str= L"str ";
_TCHAR* pWstr;
pWstr = Str .GetBuffer(0);
CString ----> LPCTSTR
CString Str= L"str";
const _TCHAR* pWstr=(LPCTSTR)Str;
LPCTSTR ----> CString
LPCTSTR lpctStr = L"str ";
CString cWstr = lpctStr;
多字节(MBCS /ANSI)转宽字节(UNICODE)
char *cmrName="中国 ";
WCHAR *str;
DWORDdwNum =MultiByteToWideChar (CP_ACP,0,cmrName, -1,NULL,0);
str =newWCHAR[dwNum];
MultiByteToWideChar(CP_ACP, 0,cmrName, -1,str,dwNum);
宽字节(UNICODE)转多字节(MBCS/ANSI)
CString str=L"中国";
int iTextLen;
iTextLen = WideCharToMultiByte(CP_UTF8,0, str, -1,NULL, 0, NULL,NULL);
char *pElementText = new char[iTextLen+ 1];
memset( ( void*)pElementText, 0, sizeof(char) * ( iTextLen + 1 ) );
WideCharToMultiByte( CP_UTF8,0,str,-1,pElementText,iTextLen,NULL,NULL);
********************************************************************************************************
*******************字符与数值转换*******************
********************************************************************************************************
Float or Double ----> CString
float fArea=12.234;
CString Str;
Str.Format(_T("%s%0.2f"),Str,fArea);
wcout<<Str.GetString();
12.23
// %s%lf double--->CString %s%f float---->CString
// %s%0.2lf %s%f0.0 设置小数点
Int or Long ----> CString
int fArea=12;
CString Str;
Str.Format(_T("%s%d"),Str,fArea);
wcout<<Str.GetString();
12
Char*----> int
char*str4="123";
intdata = (atoi)(str4);
CString ----> double
CString str=L”500.00”;
Double height = _wtof(str);
LONG nPort=_wtol(str);