
|
Hi All,
I want to covert a string to integer.Consider the string as char str[10]; and integer as int num; My case is as following:-
1) Suppose str = "10"
num should be = 10
2) Suppose str = "10.88"
num should be 0 or any invalid number so that we can identify that its not an integer but any other value.
3) Suppose str = "10ab"
num should be 0 or any invalid number so that we can identify that its not an integer but any other value.
Is there any direct API by which we can identify the above cases. I have tried atoi() but it returns the remaining integer value after removing the float or alphanumeric values.
Or
I have to try it by creating my own method.
|
|
|
|

|
Since this is the C++/CLI forum, I'll give you a Managed reply -- use the TryParse static method on Int32 and/or Double classes.
int val;
String^ s = "10.22";
if (System::Int32::TryParse(s,val))
else
John
modified 17-Jul-12 10:24am.
|
|
|
|

|
Thanks John for your reply. I am sorry I posted this thread in C++/CLI forum. Actually I was looking for a solution in C++/MFC.
Sorry for the inconvinience.
Cheers,
Abinash
|
|
|
|