#include<iostream>#include<string>#include<cctype>#pragma warning(disable:4996)using namespace std;void main(){string k("123456");cout << isdigit(k[0]);}
1 回答

慕標5832272
TA貢獻1966條經驗 獲得超4個贊
給你個例子參考:
示例:使用isdigit判斷給定字符是否為0~9的數字。
#include<iostream.h>
#include<ctype.h>
int main()
{
char c1='A';
char c2=‘1’;
if (isdigit (c1)!=0 )
cout<<c1<<" is the valid digit!"<<endl; //當c1為0~9d的數字時,打印信息
else
cout<<c1<<" is not the valid digit!"<<endl; //當c1為非0~9d的數字時,打印信息
if (isdigit (c2)!=0 )
cout<<c2<<" is the valid digit"<<endl; //當c1為0~9d的數字時,打印信息
else
cout<<c2<<" is not the valid digit!"<<endl; //當c1為非0~9d的數字時,打印信息
return 0;
}
- 1 回答
- 0 關注
- 110 瀏覽
添加回答
舉報
0/150
提交
取消