#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;