Solved

CString to int

Posted on 2004-08-10
8
17,500 Views
Last Modified: 2013-11-20
How can I convert a data of CString type into int in EVC?
0
Comment
Question by:mwcmp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:Kiran Paul VJ
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

696 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