Wednesday, January 6, 2010

Format __int64 in CString - MFC

Format int64 string using CString.


Writes formatted data to a CStringT in the same way that sprintf formats data into a C-style character array.

__int64 lMyPinCode = 691301;
__int64 lFlat = 6;
CString strMyPinCode;
strMyPinCode.Format(_T("MyPinCode = %d, Flat = %d \n"),lMyPinCode,lFlat);
_tprintf(strMyPinCode);

Output
MyPinCode = 691301, Flat = 0
Solution
Use
long long” or Int64 format Specification .
strMyPinCode.Format(_T("MyPinCode = %lld, Flat = %lld \n"),lMyPinCode,lFlat);
_tprintf(strMyPinCode);
strMyPinCode.Format(_T("MyPinCode = %I64d, Flat = %I64d \n"),lMyPinCode,lFlat);
_tprintf(strMyPinCode);
Output
MyPinCode = 691301, Flat = 6
MyPinCode = 691301, Flat = 6

 

No comments: