November 18th, 2009, 03:42 AM
#1
Convert CString to int.
I'm working with VC++ using Visual Studio.net 2008 platform.I've a previous experice working on VS 6.0 only.
in my project I want to convert a CString value to integer. The code I've used is
Code:
int ss;
CString ab=25;
sscanf(ab,"%d",&ss);
the error message that came was
"sscanf cannot convert parameter 1 from CString to const char *".
How to fix it???
November 18th, 2009, 03:52 AM
#2
Re: Convert CString to int.
I'm working with VC++ using Visual Studio.net 2008 platform
There is no such thing. Check the name again.
You call 25 a string?
You can also use atoi().
November 18th, 2009, 03:56 AM
#3
Re: Convert CString to int.
1. Use _T() macro and _t ... versions of C-runtime functions to make your code both UNICODE and ANSI aware.
2. You can also use _ttol , _ttoi , _tcstol functions.
Victor Nijegorodov
November 18th, 2009, 03:57 AM
#4
Re: Convert CString to int.
int ss;
CString ab="25";
sscanf((const char*)ab,"%d",&ss);
November 18th, 2009, 03:59 AM
#5
Re: Convert CString to int.
Version with generic text mappings, according to VictorN's note:
int ss;
CString ab=_T("25");
_stscanf((LPCTSTR)ab, _T("%d") ,&ss);
Tags for this Thread
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width
Bookmarks