How do you convert a C++ string to an int? [duplicate]
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. Randy Sugianto 'Yuku' #include <sstream> // st is input string int result; stringstream(st) >> result; Martin York Use the C++ streams. std::string plop("123"); std::stringstream str(plop); int x; str >> x; /* Lets not forget to error checking */ if (!str) { // The conversion failed. //