?
Solved

CString to int

Posted on 2004-08-10
8
Medium Priority
?
17,503 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
Industry Leaders: 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 400 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

765 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