C++中数据类型的取值,范围,我们使用到了 limits这个类
#include#include using namespace std;int main(){ cout << "type: \t\t" << "************size**************"<< endl; cout << "bool: \t\t" << "所占字节数:" << sizeof(bool); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t\t最小值:" << (numeric_limits ::min)() << endl; cout << "char: \t\t" << "所占字节数:" << sizeof(char); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t\t最小值:" << (numeric_limits ::min)() << endl; cout << "signed char: \t" << "所占字节数:" << sizeof(signed char); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t\t最小值:" << (numeric_limits ::min)() << endl; cout << "unsigned char: \t" << "所占字节数:" << sizeof(unsigned char); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t\t最小值:" << (numeric_limits ::min)() << endl; cout << "wchar_t: \t" << "所占字节数:" << sizeof(wchar_t); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t\t最小值:" << (numeric_limits ::min)() << endl; cout << "short: \t\t" << "所占字节数:" << sizeof(short); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t\t最小值:" << (numeric_limits ::min)() << endl; cout << "int: \t\t" << "所占字节数:" << sizeof(int); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t最小值:" << (numeric_limits ::min)() << endl; cout << "unsigned: \t" << "所占字节数:" << sizeof(unsigned); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t最小值:" << (numeric_limits ::min)() << endl; cout << "long: \t\t" << "所占字节数:" << sizeof(long); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t最小值:" << (numeric_limits ::min)() << endl; cout << "unsigned long: \t" << "所占字节数:" << sizeof(unsigned long); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t最小值:" << (numeric_limits ::min)() << endl; cout << "double: \t" << "所占字节数:" << sizeof(double); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t最小值:" << (numeric_limits ::min)() << endl; cout << "long double: \t" << "所占字节数:" << sizeof(long double); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t最小值:" << (numeric_limits ::min)() << endl; cout << "float: \t\t" << "所占字节数:" << sizeof(float); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t最小值:" << (numeric_limits ::min)() << endl; cout << "size_t: \t" << "所占字节数:" << sizeof(size_t); cout << "\t最大值:" << (numeric_limits ::max)(); cout << "\t最小值:" << (numeric_limits ::min)() << endl; cout << "string: \t" << "所占字节数:" << sizeof(string) << endl; // << "\t最大值:" << (numeric_limits ::max)() << "\t最小值:" << (numeric_limits ::min)() << endl; cout << "type: \t\t" << "************size**************"<< endl; return 0; }