Loading

c++基本数据类型及其取值范围

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

 

 --- 参考自的博客kilen的博客。运行结果:

posted @ 2018-10-10 16:52  Geoffrey_one  阅读(1372)  评论(0编辑  收藏  举报
/*
*/