
18 Jun
2008
18 Jun
'08
9:44 p.m.
Sean Farrow wrote:
I need to convert and std::string to an int, should I use Lexical_cast or can I just use static_cast?
You cannot use static_cast to convert an std::string to an int. But I think that lexical_cast is indeed the right thing for you. #include <boost/lexical_cast.hpp> std::string s = "42"; int i = boost::lexical_cast<int>(s); http://www.boost.org/doc/libs/release/libs/conversion/lexical_cast.htm HTH, -- Niels Dekker http://www.xs4all.nl/~nd/dekkerware Scientific programmer at LKEB, Leiden University Medical Center