?
Solved

CString to iny

Posted on 2003-11-18
8
Medium Priority
?
571 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
[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
  • 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 80 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
Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

 

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
 

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

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!

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

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