CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2008
    Posts
    59

    Question 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???

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    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.

    Code:
    CString ab=25;
    You call 25 a string?

    You can also use atoi().
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    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

  4. #4
    Join Date
    Jul 2002
    Posts
    2,543

    Re: Convert CString to int.

    int ss;
    CString ab="25";
    sscanf((const char*)ab,"%d",&ss);

  5. #5
    Join Date
    Jul 2002
    Posts
    2,543

    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
  •  





Click Here to Expand Forum to Full Width

Featured