小编use*_*836的帖子

使用'cin'读'unsigned int'

我正在尝试阅读如下unsigned int使用cin:

#include <limits.h>
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    unsigned int number;

    // UINT_MAX = 4294967295
    cout << "Please enter a number between 0 and " << UINT_MAX << ":" << endl;

    cin >> number;

    // Check if the number is a valid unsigned integer
    if ((number < 0) || ((unsigned int)number > UINT_MAX))
    {
        cout << "Invalid number." << endl;
        return -1;
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是,每当我输入一个大于无符号整数(UINT_MAX)上限的值时,程序就会显示 …

c++ windows int unsigned cin

6
推荐指数
1
解决办法
5910
查看次数

标签 统计

c++ ×1

cin ×1

int ×1

unsigned ×1

windows ×1