简介

我们写程序的时候经常遇到为某个值赋值为最大/最小值。但是有些数字很难记。这个库给你保存了你想要的极限值

参考链接

http://www.cplusplus.com/reference/limits/numeric_limits/

code

// numeric_limits example
#include <iostream>     // std::cout
#include <limits>       // std::numeric_limits

int main () {
  std::cout << std::boolalpha;
  std::cout << "Minimum value for int: " << std::numeric_limits<int>::min() << '\n';
  std::cout << "Maximum value for int: " << std::numeric_limits<int>::max() << '\n';
  std::cout << "int is signed: " << std::numeric_limits<int>::is_signed << '\n';
  std::cout << "Non-sign bits in int: " << std::numeric_limits<int>::digits << '\n';
  std::cout << "int has infinity: " << std::numeric_limits<int>::has_infinity << '\n';
  return 0;
}

result

Minimum value for int: -2147483648 // int 的最小值
Maximum value for int: 2147483647 // int 的最大值
int is signed: true
Non-sign bits in int: 31
int has infinity: false
posted on 2020-09-06 13:34  HDU李少帅  阅读(311)  评论(0编辑  收藏  举报