Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

The C++ standard library

The C++ standard library

is a header file in the C++ standard library that provides limits and characteristics related to integer types. It defines a set of constants describing various integer types (such as char, int, long ) minimum, maximum, and other related attributes. These constants come from the C standard library's header file in your C++ program.

Constants provided by

These constants describe the characteristics of different integer types on a specific platform. Here are some commonly used constants:

  1. Character type
  1. Short integer
  1. Integer
  1. Long integer
  1. Long long integer

Example

Below is an example using example program of constants defined in the header:

Example

#include

#include

int

main

(

)

{

   

// Print the max and min values of int

    std

::

cout

<<

"int max value: "

<<

INT_MAX

<<

std

::

endl

;

    std

::

cout

<<

"int min value: "

<<

INT_MIN

<<

std

::

endl

;

   

// Print the max and min values of long

    std

::

cout

<<

"long max value: "

<<

LONG_MAX

<<

std

::

endl

;

    std

::

cout

<<

"long min value: "

<<

LONG_MIN

<<

std

::

endl

;

   

// Print the max value of unsigned long

    std

::

cout

<<

"unsigned long max value: "

<<

ULONG_MAX

<<

std

::

endl

;

   

// Print the max and min values of char

    std

::

cout

<<

"char max value: "

<<

CHAR_MAX

<<

std

::

endl

;

    std

::

cout

<<

"char min value: "

<<

CHAR_MIN

<<

std

::

endl

;

   

return

0

;

}

Output result

When you run the program above, the output will be similar to the following (specific values may vary by compiler and platform):

int 的最大值是:2147483647

int 的最小值是:-2147483648

long 的最大值是:9223372036854775807

long 的最小值是:-9223372036854775808

unsigned long 的最大值是:18446744073709551615

char 的最大值是:127

char 的最小值是:-128

The constants in the header provide useful information about integer type representations, enabling programmers to write platform-independent code and ensure consistent behavior across platforms. Understanding the meaning and usage of these constants is especially important for applications requiring high precision and range control. If you have specific usage needs or questions, we can discuss further.