我试图找到这些数据类型的范围

时间:2015-06-30 02:54:58

标签: c++ 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() <<"\n\n\n\n"<< endl;

代码不断向我显示错误;我不知道我在做什么。假设显示所有这些数据类型和修饰符的大小和范围。 min继续被突出显示,我看到有关期望标识符的错误。请帮忙;我通过谷歌搜索过这么多。

2 个答案:

答案 0 :(得分:0)

您需要始终对std::命名空间中的所有名称使用std。 (或者您可以使用using namespace std;

您需要包含正确的标题:

#include <iostream>
#include <limits>

窗:

(来自#define NOMINMAX using std::min/max的信息):此外,如果您有#include <windows.h>(我认为不是必要的,但我对Windows了解的内容),则需要避免使用通过编写扩展标准minmax宏,例如:

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

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

答案 1 :(得分:0)

如果将第23行中的最低()更改为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