C++ 判断一个数是否在int的取值范围内

来源:互联网 发布:java主要用来做什么 编辑:程序博客网 时间:2024/06/05 11:07
#include <iostream>#include<climits>#include<cstdio>using namespace std;bool is_int(long long);int main(){    long long theOne;    cout << "EOF means ending"<<endl;    cout << "Please input the test number:"<<endl;    cin >> theOne;    while(theOne!=EOF)    {        if(is_int(theOne))            cout << "YES"<<endl;        else            cout << "Out of range"<<endl;        cin.clear();        cin >>theOne;    }    return 0;}bool is_int(long long x){    if(x>=INT_MIN&&x<=INT_MAX)        return true;    else        return false;}

阅读全文
0 0
原创粉丝点击