Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++: max integer [duplicate]

Tags:

c++

Is there a C++ cross-platform library that provides me with a portable maximum integer number?

I want to declare:

const int MAX_NUM = /* call some library here */; 

I use MSVC 2008 unmanaged.

like image 886
sivabudh Avatar asked Nov 13 '09 21:11

sivabudh


2 Answers

In the C++ standard library header <limits>, you will find:

std::numeric_limits<int>::max() 

Which will tell you the maximum value that can be stored in a variable of type int. numeric_limits is a class template, and you can pass it any of the numeric types to get the maximum value that they can hold.

The numeric_limits class template has a lot of other information about numeric types as well.

like image 160
James McNellis Avatar answered Sep 28 '22 04:09

James McNellis


See limits.h (C) or climits (C++). In this case you would want the INT_MAX constant.

like image 44
Lukáš Lalinský Avatar answered Sep 28 '22 03:09

Lukáš Lalinský