How to extract integer value from CString
-
Hello All, I have to get integer value which is stored in a CString object. My code
CString str = "-123"; int i; sscanf (str, "%d", &i);
This is what i followed. Is there any better approach than this? Thanks for your time Ravi -
Hello All, I have to get integer value which is stored in a CString object. My code
CString str = "-123"; int i; sscanf (str, "%d", &i);
This is what i followed. Is there any better approach than this? Thanks for your time RaviTry this Ravi: CString str = "-123"; int i = atoi((LPCSTR)str); If it didn't work, simply remove '(LPCSTR)'
-
Hello All, I have to get integer value which is stored in a CString object. My code
CString str = "-123"; int i; sscanf (str, "%d", &i);
This is what i followed. Is there any better approach than this? Thanks for your time Ravi -
Hi Ravi, We have ready made function for data conversion. You can use the following function to convert CString to int. CString str = "-123"; int i = atoi(str); This may be helpful you. Regards, Venkat
-
we can use that CString class method such as string Format CString str = " "; int i; i = str.Format("%d",str);
maheswara wrote: i = str.Format("%d",str); CString::Format() dosen't return any value.
suhredayan
There is no spoon. -
Hi Ravi, We have ready made function for data conversion. You can use the following function to convert CString to int. CString str = "-123"; int i = atoi(str); This may be helpful you. Regards, Venkat
Venkat Bodapati wrote: We have ready made function for data conversion. [...] int i = atoi(str); :laugh::laugh: you wrote atoi() ??? wow, great... i'd be very curious to see the source (YOUR source) ... !
TOXCCT >>> GEII power
[toxcct][VisualCalc] -
we can use that CString class method such as string Format CString str = " "; int i; i = str.Format("%d",str);
no,
CString::Format()
only formats a string with some parameters to put into the CString object... there's no function into the CString class to make the opposite operation. moreover, here is what MSDN tells us :void __cdecl Format(
UINT nFormatID,
[, argument]...
);
void __cdecl Format(
PCXSTR pszFormat,
[, argument]...
);CString::Format()
don't return anything !!
TOXCCT >>> GEII power
[toxcct][VisualCalc] -
maheswara wrote: i = str.Format("%d",str); CString::Format() dosen't return any value.
suhredayan
There is no spoon. -
-
Try this Ravi: CString str = "-123"; int i = atoi((LPCSTR)str); If it didn't work, simply remove '(LPCSTR)'