CString to iny

Posted on 2003-11-18
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 ?????
Question by:p_vladimir
  • 4
  • 3
LVL 19

Expert Comment

ID: 9774023

> 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,
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()
LVL 19

Accepted Solution

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);

Expert Comment

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*"
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!


Expert Comment

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

Expert Comment

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 ;)
LVL 19

Expert Comment

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


Expert Comment

ID: 9819618
k cool :)

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Need Help INsttalling wget on Mavericks OS X 3 81
Running shell command from Access 3 63
has22 challenge 11 71
either24  challenge 19 84
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: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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 video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

707 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

14 Experts available now in Live!

Get 1:1 Help Now