Solved

CString to int

Posted on 2004-08-10
8
17,492 Views
Last Modified: 2013-11-20
How can I convert a data of CString type into int in EVC?
0
Comment
Question by:mwcmp
8 Comments
 
LVL 5

Expert Comment

by:millsoft
ID: 11766642

CString s;
int x;
x = atoi( (LPCTSTR) s );
0
 
LVL 86

Expert Comment

by:jkr
ID: 11766653
You could use

#include <stdlib.h>

CString str = "42";
int i = atoi((LPCTSTR)str);
0
 

Author Comment

by:mwcmp
ID: 11769514
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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 16

Expert Comment

by:kiranvj
ID: 11769573
0
 

Author Comment

by:mwcmp
ID: 11769670
but I am using a CString.
CString to int.
Not char to int.
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 100 total points
ID: 11770455
The following works here

      CString s(_T("123"));
      int i = _ttoi(s);
i now has the value 123
0
 

Author Comment

by:mwcmp
ID: 11776093
thanks! :)
0
 

Author Comment

by:mwcmp
ID: 11807657
.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Separate files macro - Errors on larger data set 18 69
method notes when mouse over in eclipse 5 86
scoreUp challenge 14 61
wordcount challenge 11 121
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

805 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question