1 #include<iostream> 2 #include<string> 3 #include <limits> 4 using namespace std; 5 6 int main() 7 { 8 cout << "type: " << "************size**************" << endl; 9 cout << "bool: " << "所占字节数:" << sizeof(bool); 10 cout << " 最大值:" << (numeric_limits<bool>::max)(); 11 cout << " 最小值:" << (numeric_limits<bool>::min)() << endl; 12 13 cout << "char: " << "所占字节数:" << sizeof(char); 14 cout << " 最大值:" << (numeric_limits<char>::max)(); 15 cout << " 最小值:" << (numeric_limits<char>::min)() << endl; 16 17 cout << "signed char: " << "所占字节数:" << sizeof(signed char); 18 cout << " 最大值:" << (numeric_limits<signed char>::max)(); 19 cout << " 最小值:" << (numeric_limits<signed char>::min)() << endl; 20 21 cout << "unsigned char: " << "所占字节数:" << sizeof(unsigned char); 22 cout << " 最大值:" << (numeric_limits<unsigned char>::max)(); 23 cout << " 最小值:" << (numeric_limits<unsigned char>::min)() << endl; 24 25 cout << "wchar_t: " << "所占字节数:" << sizeof(wchar_t); 26 cout << " 最大值:" << (numeric_limits<wchar_t>::max)(); 27 cout << " 最小值:" << (numeric_limits<wchar_t>::min)() << endl; 28 29 cout << "short: " << "所占字节数:" << sizeof(short); 30 cout << " 最大值:" << (numeric_limits<short>::max)(); 31 cout << " 最小值:" << (numeric_limits<short>::min)() << endl; 32 33 cout << "int: " << "所占字节数:" << sizeof(int); 34 cout << " 最大值:" << (numeric_limits<int>::max)(); 35 cout << " 最小值:" << (numeric_limits<int>::min)() << endl; 36 37 cout << "unsigned: " << "所占字节数:" << sizeof(unsigned); 38 cout << " 最大值:" << (numeric_limits<unsigned>::max)(); 39 cout << " 最小值:" << (numeric_limits<unsigned>::min)() << endl; 40 41 cout << "long: " << "所占字节数:" << sizeof(long); 42 cout << " 最大值:" << (numeric_limits<long>::max)(); 43 cout << " 最小值:" << (numeric_limits<long>::min)() << endl; 44 45 cout << "long long: " << "所占字节数:" << sizeof(long long); 46 cout << " 最大值:" << (numeric_limits<long long>::max)(); 47 cout << " 最小值:" << (numeric_limits<long long>::min)() << endl; 48 49 cout << "unsigned long: " << "所占字节数:" << sizeof(unsigned long); 50 cout << " 最大值:" << (numeric_limits<unsigned long>::max)(); 51 cout << " 最小值:" << (numeric_limits<unsigned long>::min)() << endl; 52 53 cout << "double: " << "所占字节数:" << sizeof(double); 54 cout << " 最大值:" << (numeric_limits<double>::max)(); 55 cout << " 最小值:" << (numeric_limits<double>::min)() << endl; 56 57 cout << "long double: " << "所占字节数:" << sizeof(long double); 58 cout << " 最大值:" << (numeric_limits<long double>::max)(); 59 cout << " 最小值:" << (numeric_limits<long double>::min)() << endl; 60 61 cout << "float: " << "所占字节数:" << sizeof(float); 62 cout << " 最大值:" << (numeric_limits<float>::max)(); 63 cout << " 最小值:" << (numeric_limits<float>::min)() << endl; 64 65 cout << "size_t: " << "所占字节数:" << sizeof(size_t); 66 cout << " 最大值:" << (numeric_limits<size_t>::max)(); 67 cout << " 最小值:" << (numeric_limits<size_t>::min)() << endl; 68 69 cout << "string: " << "所占字节数:" << sizeof(string) << endl; 70 // << " 最大值:" << (numeric_limits<string>::max)() << " 最小值:" << (numeric_limits<string>::min)() << endl; 71 cout << " " << "************size**************" << endl; 72 return 0; 73 }
--- 参考自的博客kilen的博客。运行结果: