Is there a way to convert a string (class string) to int in c++, Other than atoi()? I mean is there a function writen, specially for C++, that does that?
There is a C++ way:
[tt]
#include <sstream>
std::string s="123";
int i;
(std::istringstream)s >> i;
[/tt]
But it's not as convenient (nor as fast, presumably) as atoi.
[tt]lexical_cast[/tt] function template takes the stringstream technique and encapsulates it into an easy-to-use package that works as you'd expect for anything that has sensible << and >> operators.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.