1. 程式人生 > >判斷輸入是數字還是字串

判斷輸入是數字還是字串

#include <iostream>
using namespace std;
int main()
{
while(true)
{ char temp;
cin >> temp;
if ( (temp <= 'Z' && temp >= 'A') || (temp <= 'z' && temp >= 'a') )
cout << temp << " is character" << endl;
else if (temp >= '0' && temp <= '9')
cout << temp << " is number" << endl;
}
}