Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) GetMaxInt

 

GetMaxInt is a checking code snippet to get the maximal value of an int.

 

GetMaxInt has two flavors:

  1. STL GetMaxInt
  2. Boost GetMaxInt

 

 

 

 

 

STL GetMaxInt

 

#include <limits>

///GetMaxInt returns the highest possible value of a int.
///From http://www.richelbilderbeek.nl/CppGetMaxInt.htm
int GetMaxInt()
{
  return std::numeric_limits<int>::max();
}

 

 

 

 

 

Boost GetMaxInt

 

#include <boost/numeric/conversion/bounds.hpp>

///GetMaxInt returns the highest possible value of a int.
///From http://www.richelbilderbeek.nl/CppGetMaxInt.htm
int GetMaxInt()
{
  return boost::numeric::bounds<int>::highest();
}

 

 

 

 

 

GetMaxInt test

 

#include <iostream>

int main()
{
  std::cout << "Max int: " << GetMaxInt() << std::endl;
}

 

Screen output:

 

Max int: 2147483647

 

 

 

 

 

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

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict