[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 17508
  • Last Modified:

CString to int

How can I convert a data of CString type into int in EVC?
0
mwcmp
Asked:
mwcmp
1 Solution
 
millsoftCommented:

CString s;
int x;
x = atoi( (LPCTSTR) s );
0
 
jkrCommented:
You could use

#include <stdlib.h>

CString str = "42";
int i = atoi((LPCTSTR)str);
0
 
mwcmpAuthor Commented:
error C2664: 'atoi' : cannot convert parameter 1 from 'const unsigned short *' to 'const char *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Kiran Paul VJComputer EngineerCommented:
0
 
mwcmpAuthor Commented:
but I am using a CString.
CString to int.
Not char to int.
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
The following works here

      CString s(_T("123"));
      int i = _ttoi(s);
i now has the value 123
0
 
mwcmpAuthor Commented:
thanks! :)
0
 
mwcmpAuthor Commented:
.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now