Boost logo

Boost Users :

From: Niels Dekker - mail address until 2008-12-31 (nd_mail_address_valid_until_2008-12-31_at_[hidden])
Date: 2008-06-18 17:44:26


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

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net