在climits中有类似一下的语句:
#define INT_MAX 32767
INT_MAX使用实例:
#include <iostream>
#include <climits>
using namespace std;
bool is_int(double x);
int main()
{
double num;
int result;
cout << "Enter an integer: ";
cin >> num;
while(!is_int(num))
{
cout << "Your input is not an integer\n" << "Please enter an integer: ";
cin >> num;
}
result = (int)num;
cout << "You've entered the integer " << result << endl << "Bye!\n";
return 0;
}
bool is_int(double x)
{
if(x < INT_MAX && x > INT_MIN)
return true;
else
return false;
}