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);


Niels Dekker
Scientific programmer at LKEB, Leiden University Medical Center

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at