自学内容网 自学内容网

c++11~c++20 numeric_limits

在c++中应该尽量少使用宏,用模板取而代之是明知的选择。我们可以使用numeric_limits来获取最大值和最小值,例如

#include <iostream>
#include <limits>
#include <iostream>
using namespace std;

int main()
{
cout << "int_max:"<<std::numeric_limits<int>::max() << endl;
cout << "INT_MAX:" << INT_MAX << endl;
cout << "long long_min:" << std::numeric_limits<long long>::min() << endl;
cout << "unsigned long long_max:" << std::numeric_limits<unsigned long long>::max() << endl;

system("pause");
return 0;
}

结果:
在这里插入图片描述


原文地址:https://blog.csdn.net/FairLikeSnow/article/details/142614366

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!