我正在尝试查找这些数据类型的范围

I am trying to find the range of these data types

本文关键字:数据类型 范围 查找      更新时间:2023-10-16
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一直被突出显示,我看到了有关期望标识符的错误。请帮忙;我在谷歌上搜索了很多。

如果将第23行的lowest((更改为min((,则CODE工作正常。您是否包含了限制标题?这就是我得到的输出:
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了解多少(,你需要避免非标准的minmax宏通过编写来扩展,例如:

(std::numeric_limits<long double>::min)()

或者,显然,您可以在任何#include之前使用#define NOMINMAX