Dain

写出一个可以工作的程序并不够

统计

留言簿(3)

积分与排名

良师益友

阅读排行榜

评论排行榜

Getting the Minimum and Maximum Values for a Numeric Type

Getting numeric limits

#include <iostream>
#include 
<limits>

using namespace std;

template
<typename T>
void showMinMax() {
   cout 
<< "min: " << numeric_limits<T>::min() << endl;
   cout 
<< "max: " << numeric_limits<T>::max() << endl;
   cout 
<< endl;
}


int main() {
   cout 
<< "short:" << endl;
   showMinMax
<short>();
   cout 
<< "int:" << endl;
   showMinMax
<int>();
   cout 
<< "long:" << endl;
   showMinMax
<long>();
   cout 
<< "long long:" << endl;
   showMinMax
<long long>();
   cout 
<< "float:" << endl;
   showMinMax
<float>();
   cout 
<< "double:" << endl;
   showMinMax
<double>();
   cout 
<< "long double:" << endl;
   showMinMax
<long double>();
   cout 
<< "unsigned short:" << endl;
   showMinMax
<unsigned short>();
   cout 
<< "unsigned int:" << endl;
   showMinMax
<unsigned int>();
   cout 
<< "unsigned long:" << endl;
   showMinMax
<unsigned long>();
   cout 
<< "unsigned long long:" << endl;
   showMinMax
<unsigned long long>();
}

posted on 2007-05-29 10:38 Dain 阅读(747) 评论(2)  编辑 收藏 引用 所属分类: 笔记

评论

# re: Getting the Minimum and Maximum Values for a Numeric Type 2007-05-29 11:00 梦在天涯

恩,不错,模版使用恰当!  回复  更多评论   

# re: Getting the Minimum and Maximum Values for a Numeric Type 2007-05-29 11:57 Dain

@梦在天涯
3x  回复  更多评论   


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理