• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 17509
  • 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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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