今天做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