Possible Duplicate:
How to parse a string to an int in C++?
How do you convert a C++ string to an int?
Assume you are expecting the string to have actual numbers in it ("1", "345", "38944", for example).
Also, let's assume you don't have boost, and you really want to do it the C++ way, not the crufty old C way.
Use the C++ streams.
PS. This basic principle is how the boost library
lexical_cast<>
works.My favorite method is the boost
lexical_cast<>
It provides a method to convert between a string and number formats and back again. Underneath it uses a string stream so anything that can be marshaled into a stream and then un-marshaled from a stream (Take a look at the >> and << operators).
in "stdapi.h"
This function tells you the result, and how many characters participated in the conversion.