Solved

CString to iny

Posted on 2003-11-18
8
519 Views
Last Modified: 2013-11-20
Can i convert an CString to int. Example i have string str "123" and how should i convert him to int 123 ?????
0
Comment
Question by:p_vladimir
  • 4
  • 3
8 Comments
 
LVL 19

Expert Comment

by:Dexstar
ID: 9774023
p_vladimir:

> Can i convert an CString to int. Example i have string str "123" and how should
> i convert him to int 123 ?????

CString str = "123";
int i = atoi(str);

Hope That Helps,
Dex*
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 9775132
atoi() will work as long as you are not using Unicode (or MBCS) strings. In this case, you need to use _wtoi()
0
 
LVL 19

Accepted Solution

by:
Dexstar earned 20 total points
ID: 9775184
Actually, use _ttoi and then the compiler will work out the UNICODE / Ansi string issues for you.

CString str = "123";
int i = _ttoi(str);
0
 

Expert Comment

by:Drew_Benton
ID: 9808455
Even though the points have been awarded, heres how you do it using atoi().

int i = atoi(str.operator LPCTSTR());

*This works b/c LPCSTR is a "char*"
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Expert Comment

by:Drew_Benton
ID: 9808461
Ops i appologize to Dexstar, read the page yet missed his comment, sry!
0
 

Expert Comment

by:Drew_Benton
ID: 9808469
Now i gotta appologize for the generic use of "his"...*sigh* late night programming and forum responding mix as well as derefrencing the NULL pointer ;)
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9819169
No apology necessary...  I'm a guy.  :)

D*
0
 

Expert Comment

by:Drew_Benton
ID: 9819618
k cool :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Process filename extension 3 172
abstract class with all non abstract mentods 6 76
scoreUp challenge 14 57
JQuery serialize and unserialize 8 50
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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now