Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


CString to iny

Posted on 2003-11-18
Medium Priority
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
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
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 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);
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


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*"

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

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: 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…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

609 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