也是在csdn里记下来的:
Hexa To Decimal :-
------------------
a)
You can use strtol function and you can specify base.
char * hexstring= "ABCDEF";
char * p;
int number = strtol(hexstring, &p,16);
char hexstring[10];
int number = 30;
itoa( number, hexstring, 16);
In hexstring is 1e.
Hexa To Decimal :-
------------------
a)
You can use strtol function and you can specify base.
char * hexstring= "ABCDEF";
char * p;
int number = strtol(hexstring, &p,16);
Double to CString including the fractional part :-
--------------------------------------------------
CString strValue,strInt, strDecimal;
int decimal,sign;
double dValue = 4.125;
strValue = _fcvt(dValue,6,&decimal,&sign); // Now decimal contains 1 because there is only one digit before the .
strInt = strValue.Left(decimal); // strInt contains 4
strDecimal = strValue.Mid(decimal); // strDecimal contains 125
CString str1 = _T("My String");
int nLen = str1.GetLength();
LPCSTR lpszBuf = str1.GetBuffer(nLen);
// here do something with lpszBuf...........
str1.ReleaseBuffer();
CString to LPSTR :-
--------------------
CString str = _T("My String");
int nLen = str.GetLength();
LPTSTR lpszBuf = str.GetBuffer(nLen);
// here do something with lpszBuf...........
str.ReleaseBuffer();
CString to WCHAR*
-----------------
CString str = "A string here" ;
LPWSTR lpszW = new WCHAR[255];
Char* to BSTR
-------------
char * p = "whatever";
_bstr_t bstr = p;
Float to WORD and Vice Versa
-----------------------------
float fVar;
WORD wVar;
fVar = 247.346;
wVar = (WORD)fVar; //Converting from float to WORD. The value in wVar would be 247
wVar = 247;
fVar = (float)fVar; //Converting from WORD to float. The value in fVar would be 247.00