数字溢出时,Cin无法工作 [英] Cin can't work when number overflow

查看:75
本文介绍了数字溢出时,Cin无法工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查长数据类型的数字。

以下是我的代码。问题是如果我输入的数字高于9,223,372,036,854,775,807,函数将不会停在cin,所以循环电路将继续运行。



我是什么尝试过:



I want to check the number with long long data type.
Below is my code. The problem is if I input the number higher than 9,223,372,036,854,775,807, the function won't stop at cin, so the loop circuit will keep going.

What I have tried:

#include <iostream>

using namespace std;

// A[100]={0};
long long number=0;

int main()
{
    for(int x=0; x<1000;x++)
        {
        cout<<"enter a number";
        cin>>number;
        long long Number_out=number;
        cout<<endl<<"Number out"<<Number_out<<endl;
        }
}

推荐答案

尝试将其与__int32,__ int64数据类型一起使用。
Try to use it with __int32, __int64 datatypes.


使用long double ... variable type
use long double ... variable type


这篇关于数字溢出时,Cin无法工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆