Possible Duplicate:
Convert string to int C++
What’s the fastest way to check if a string is a number?
I need to convert string to int and I need to know if converting was successful. But number can be zero, so I can’t use atoi and others. String to convert I read from file.
you can use this template function, but this is not just for converting a string to an int – it is to convert a string to every type:
If you want to now if the convert was successfull, then return a specific value in the if
iss.fail()or pass a second reference argument to the function and set the value to false if it failed.You can use it like this:
If you like the solution with the reference argument, here an example: