numeric_limits(转载)

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

int main()
{
    //判断各类型有无极值
    cout << boolalpha;
    cout << "specialized(char): "
      << numeric_limits<char>::is_specialized
        << endl;
    cout << "specialized(wchar_t): "
      << numeric_limits<wchar_t>::is_specialized
        << endl;
   cout << "specialized(string): "
      << numeric_limits<string>::is_specialized
        << endl;
    cout << noboolalpha << endl;
   
    //各个类型的最大值
    cout << "max(int): "
         << numeric_limits<int>::max()
         << endl;
    cout << "max(short): "
         << numeric_limits<short>::max()
         << endl;
    cout << "max(unsigned int): "
         << numeric_limits<unsigned int>::max()
         << endl;
    cout << "max(unsigned short): "
         << numeric_limits<unsigned short>::max()
         << endl;
    cout << "max(unsigned long): "
         << numeric_limits<unsigned long>::max()
         << endl;
    cout << "max(long): "
         << numeric_limits<long>::max()
         << endl;
    cout << "max(long long): "
         << numeric_limits<long long>::max()
         << endl;
    cout << "max(float): "
         << numeric_limits<float>::max()
         << endl;
    cout << "max(double): "
         << numeric_limits<double>::max()
         << endl;
    cout << "max(long double): "
         << numeric_limits<long double>::max()
         << endl;
    cout << endl;
        
     //各个类型的最小值
    cout << "min(int): "
         << numeric_limits<int>::min()
         << endl;
    cout << "min(short): "
         << numeric_limits<short>::min()
         << endl;
    cout << "min(unsigned int): "
         << numeric_limits<unsigned int>::min()
         << endl;
    cout << "min(unsigned short): "
         << numeric_limits<unsigned short>::min()
         << endl;
    cout << "min(unsigned long): "
         << numeric_limits<unsigned long>::min()
         << endl;
    cout << "min(long): "
         << numeric_limits<long>::min()
         << endl;
    cout << "min(long long): "
         << numeric_limits<long long>::min()
         << endl;
    cout << "min(float): "
         << numeric_limits<float>::min()
         << endl;
    cout << "min(double): "
         << numeric_limits<double>::min()
         << endl;
    cout << "min(long double): "
         << numeric_limits<long double>::min()
         << endl;
   
    system("pause");    
    return 0;    
}

转载自http://blog.csdn.net/owl2008

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值