关于numeric_limits

本文介绍了C++中numeric_limits模板类的使用,用于获取各种类型的最大值、最小值等信息。作者在实践中遇到float最小值为正的问题,并探讨了可能的原因。同时,文章包含了优快云论坛上的讨论,解释了为何可以直接调用模板类的静态成员函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天做BS的TC++PL第四章的习题,有一个求各种类型的最大最小值的题,要用到 numeric_limits<class   T>模版类,做完题以后,查了一下该模版类的用法,在本文做个总结。

我的求各种类型范围的函数:

void range()
{
 cout<<"largest int = = "<<numeric_limits<int>::max()<<endl;
 cout<<"smallest int = = "<<numeric_limits<int>::min()<<endl;
 cout<<"largest char = = "<<int(numeric_limits<char>::max())<<endl;
 cout<<"smallest char = = "<<int(numeric_limits<char>::min())<<endl;
 cout<<"largest short = = "<<numeric_limits<short>::max()<<endl;
 cout<<"smallest short = = "<<numeric_limits<short>::min()<<endl;
 cout<<"largest long = = "<<numeric_limits<long>::max()<<endl;
 cout<<"smallest long = = "<<numeric_limits<long>::min()<<endl;
 cout<<"largest float = = "<<numeric_limits<float>::max()<<endl;
 cout<<"smallest float = = "<<numeric_limits<float>::min()<<endl;
 cout<<"largest double = = "<<numeric_limits<double>::max()<<endl;
 cout<<"smallest double = = "<<numeric_limits<double>::min()<<endl;
 cout<<"largest long double = = "<<numeric_limits<long double>::max()<<endl;
 cout<<"smallest long double = = "<&l

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值