Solved

CString to iny

Posted on 2003-11-18
8
542 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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: 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 …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

839 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