Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) ToInt

 

ToInt is a convert code snippet to convert std::string to int.

 

LexicalCast and boost::lexical_cast are more general then ToInt and convert a std::string to any data type.

 

#include <string>

///ToInt converts a std::string to an integer
///From http://www.richelbilderbeek.nl/CppToInt.htm
const int ToInt(const std::string& s)
{
  return std::atoi(s.c_str());
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict