我正在尝试查找这些数据类型的范围
I am trying to find the range of these data types
cout <<"The size of a integer is " << sizeof(int) << "bytes and the range is: " << INT_MIN << " to " << INT_MAX <<endl;
cout <<"The size of an unsigned integer is " <<sizeof(unsigned int) << "bytes and the range is: "
<<std::numeric_limits<unsigned int>::min() << " to " <<std::numeric_limits<unsigned int>::max() <<endl;
std::cout <<"The size of a short integer is " <<sizeof(short int) << "bytes and the range is: "
<<std::numeric_limits<short int>::min() << " to " <<std::numeric_limits<short int>::max() <<endl;
cout <<"The size of an unsigned short integer is " <<sizeof(unsigned short int) << "bytes and the range is: "
<<std::numeric_limits<unsigned short int>::min() << " to " << std::numeric_limits<unsigned short int>::max() <<endl;
cout <<"The size of an long integer is " << sizeof(long int) << "bytes and the range is: "
<< std::numeric_limits<long int>::min() << " to " << std::numeric_limits<long int>::max() << endl;
cout << "The size of an unsigned long integer is " << sizeof(unsigned long int) << "bytes and the range is: "
<<std::numeric_limits<unsigned long int>::min() << " to " << std::numeric_limits<unsigned long int>::max() << endl;
cout << "The size of a character is " << sizeof(char) << "bytes and the range is: "
<<std::numeric_limits<char>::min() << " to " << std::numeric_limits<char>::max() << endl;
cout << "The size of a unsigned character is " << sizeof(unsigned char) << "bytes and the range is: "
<<std::numeric_limits<unsigned int>::min() << " to " << std::numeric_limits<unsigned int>::max() << endl;
std::cout << "The size of a float is " << sizeof(float) << "bytes and the range is: "
<<std::numeric_limits<float>::lowest() << " to " << std::numeric_limits<float>::max() << endl;
cout << "The size of a wchar_t is " << sizeof(wchar_t) << "bytes and the range is: "
<<std::numeric_limits<wchar_t>::min() << " to " << std::numeric_limits<wchar_t>::max() << endl;
cout << "The size of a double is " << sizeof(double) << "bytes and the range is: "
<<std::numeric_limits<double>::min() << " to " << std::numeric_limits<double>::max() << endl;
cout << "The size of a long double is " << sizeof(long double) << "bytes and the range is: "
<<std::numeric_limits<long double>::min() << " to " << std::numeric_limits<long double>::max() << endl;
cout << "The size of a long is " << sizeof(long) << "bytes and the range is: "
<<std::numeric_limits<long>::min() << " to " << std::numeric_limits<long>::max() << endl;
cout << "The size of an unsingned long is " << sizeof(unsigned long) << "bytes and the range is: "
<<std::numeric_limits<unsigned long>::min() << " to " << std::numeric_limits<unsigned long>::max() << endl;
cout << "The size of a long long is " << sizeof(long long) << "bytes and the range is: "
<<std::numeric_limits<long long>::min() << " to " << std::numeric_limits<long long>::max() << endl;
cout << "The size of an unsingned long long is " << sizeof(unsigned long long) << "bytes and the range is: "
<<std::numeric_limits<unsigned int>::min() << " to " << std::numeric_limits<unsigned int>::max() << endl;
cout << "The size of a boolean is " << sizeof(bool) << "bytes and the range is: " <<std::numeric_limits<bool>::min() << " to "
<< std::numeric_limits<bool>::max() <<"nnnn"<< endl;
代码不断向我显示错误;我不知道我在做什么。假设它向我显示所有这些数据类型和修饰符的大小和范围。min一直被突出显示,我看到了有关期望标识符的错误。请帮忙;我在谷歌上搜索了很多。
The size of an unsigned integer is 4bytes and the range is: 0 to 4294967295
The size of a short integer is 2bytes and the range is: -32768 to 32767
The size of an unsigned short integer is 2bytes and the range is: 0 to 65535
The size of an long integer is 8bytes and the range is: -9223372036854775808 to 9223372036854775807
The size of an unsigned long integer is 8bytes and the range is: 0 to 18446744073709551615
The size of a character is 1bytes and the range is: � to
The size of a unsigned character is 1bytes and the range is: 0 to 4294967295
The size of a float is 4bytes and the range is: 1.17549e-38 to 3.40282e+38
The size of a wchar_t is 4bytes and the range is: -2147483648 to 2147483647
The size of a double is 8bytes and the range is: 2.22507e-308 to 1.79769e+308
The size of a long double is 16bytes and the range is: 3.3621e-4932 to 1.18973e+4932
The size of a long is 8bytes and the range is: -9223372036854775808 to 9223372036854775807
The size of an unsingned long is 8bytes and the range is: 0 to 18446744073709551615
The size of a long long is 8bytes and the range is: -9223372036854775808 to 9223372036854775807
The size of an unsingned long long is 8bytes and the range is: 0 to 4294967295
The size of a boolean is 1bytes and the range is: 0 to 1
您需要对std
命名空间中的所有名称一致使用std::
。(也可以使用using namespace std;
(
你需要包括正确的标题:
#include <iostream>
#include <limits>
Windows:
(信息取自#define NOMINMAX using std::min/max(:此外,如果你有#include <windows.h>
(我认为这不是必要的,但我对Windows了解多少(,你需要避免非标准的min
和max
宏通过编写来扩展,例如:
(std::numeric_limits<long double>::min)()
或者,显然,您可以在任何#include
之前使用#define NOMINMAX
。
相关文章:
- 防止主数据类型C++的隐式转换
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 在C++中打印指向不同基元数据类型的指针的内存地址
- 如何计算数据类型的范围,例如int
- C++数据类型 s 及其范围
- C++,"由于数据类型范围有限,比较总是正确的"
- C++中最大的数据类型范围
- 在 c++ 中确定某个值是否在该数据类型的最大范围内
- 当数字可能超出C++中特定数据类型的范围时如何处理异常?
- OpenCV-浮动数据类型和强度范围在0-255范围内的RGB通道
- 运算符重载中变量的数据类型和范围应该是什么
- 小数、双精度、整数等数据类型的范围
- 32位或64位操作系统如何影响数据类型范围
- GCC:由于数据类型范围有限,比较始终为真 - 在模板参数中
- 如何查找数据类型的范围
- 用于确定有符号和无符号数据类型C++的范围的公式
- 由于数据类型的范围有限,比较总是错误的
- "Float"数据类型的范围值(以C++为单位)
- 根据什么决定任何数据类型的大小和范围
- 我正在尝试查找这些数据类型的范围