#include<iostream>
#include<limits>
using namespace std;
int main()
{
cout << "min:" << numeric_limits<char>::min() << " max:" << numeric_limits<char>::max() << endl;
cout << "min:" << numeric_limits<short>::min() << " max:" << numeric_limits<short>::max() << endl;
cout << "min:" << numeric_limits<int>::min() << " max:" << numeric_limits<int>::max() << endl;
cout << "min:" << numeric_limits<long>::min() << " max:" << numeric_limits<long>::max() << endl;
cout << "min:" << numeric_limits<float>::min() << " max:" << numeric_limits<float>::max() << endl;
cout << "min:" << numeric_limits<double>::min() << " max:" << numeric_limits<double>::max() << endl;
cout << "min:" << numeric_limits<long double>::min() << " max:" << numeric_limits<long double>::max() << endl;
cout << "min:" << numeric_limits<unsigned>::min() << " max:" << numeric_limits<unsigned>::max() << endl;
return 0;
}
结果发现char的最大最小值输出为奇怪的符号,最后对char输出强制转化为int类型后即可得到结果。
cout << "min:" << (int)numeric_limits<char>::min() << " max:" << (int)numeric_limits<char>::max() << endl;