Skip to content

Latest commit

 

History

History
33 lines (26 loc) · 1.25 KB

CppBoostLexical_cast.md

File metadata and controls

33 lines (26 loc) · 1.25 KB

boost::lexical_cast is a Boost function to convert to/from std::string to/from (possibly) any data type. CanLexicalCast can check if this conversion is possible.

The C++11 equivalent to convert to a std::string is std::to_string.

#include <string>
#include <boost/lexical_cast.hpp>

int main()
{
  const std::string s = "12.34";
  const double d = boost::lexical_cast<double>(s);
}

LexicalCast serves the same purpose as boost::lexical_cast, but does not use Boost and does not throw an exception when conversion fails. Note that there are differences between LexicalCast and boost::lexical_cast, as boost::lexical_cast is more strict.

External links