Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) IsInt

 

IsInt is a checking code snippet to check if a std::string can be converted to an integer.

 

CanCast and CanLexicalCast are more general versions of IsInt.

 

#include <sstream>

///IsInt determines if std::string can be converted to integer.
///From http://www.richelbilderbeek.nl/CppIsInt.htm
bool IsInt(const std::string& s)
{
  std::istringstream i(s);
  int temp;
  return (i >> temp) ? true : false;
}

 

 

 

 

 

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

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict