在C++中,各个基本类型的数值范围可以用< limits > 中的库函数中来取得。
取得的方式如下:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <limits>
using namespace std;
int main()
{
cout << "int类型的最大值:" << numeric_limits<int>::max() << endl;
cout << "int类型的最小值:" << numeric_limits<int>::min() << endl;
return 0;
}
函数执行结果如下:
int类型的最大值:2147483647
int类型的最小值:-2147483648
如果要求其他类型的最大、最小值,直接替换数值类型即可。
谢谢阅读