• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

String to Integer.

hi,
 I am reading an integer from a file by a CString variable. I want to pass this parameter to a routine which accepts integer.
So how do I convert the read string (which is a read as string) to integer ?
0
mkjoshi
Asked:
mkjoshi
1 Solution
 
V_BapatCommented:
Hi Joshi
Use CString::Format().

Example:
long lNum = 111;
CString strString;

strString.Format("%d", lNum);

Vicky
0
 
MeybeCommented:
it is very simple:)
simply use the atoi() function. and it will work fine:)

example:
CString str("10");
int i = atoi(str);

// now call your function
YourFunction (i);

Regards
0
 
atti75Commented:

Hy!

Vicky> mkjoshi wants the reverse operation... int from string

 use this:
CString str = "1234";
int i;

i = atoi(LPCTSTR(str));

you can see MSDN for more help...
Good Luck!

0
 
V_BapatCommented:
atti75: You are right.

Sorry guys.

Yes. atoi() is the answer.
0
 
mkjoshiAuthor Commented:
THANKS A  LOT!,
     You made my work simple....
Have a nice time with VC++
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now