vc 判断一个字符串是否位数字,且判断此数字的范围

来源:互联网 发布:linux 查看死机原因 编辑:程序博客网 时间:2024/05/22 15:25

//返回1正确,返回0不是

以为是判断端口的,数字范围设在了1-65535

一下是函数代码:

//返回1正确,返回0错误int isRight(CString str){BOOL bIsDigit = TRUE;int nCount = str.GetLength(); // 获得字符个数for ( int i = 0; i < nCount; i ++ ){if ( 0 == isdigit( str.GetAt(i) ) ) // 不是数字就置标志位{return 0;}}int temp = atoi(str);if (temp>0 && temp < 65536){return 1;}return 0;}


原创粉丝点击