VC++如何判断字符串是否有全为数字void CheckString( CString str )
{
BOOL bIsDigit = TRUE;
int nCount = str.GetLength(); // 获得字符个数
for ( int i = 0; i < nCount; i ++ )
{
if ( 0 == isdigit( str.GetAt(i) ) ) // 不是数字就置标志位
{
bIsDigit = FALSE;
break;// 退出
}
}
if ( bIsDigit ) //如果始终是,那么表⽰全是数字,给予提⽰
{
::MessageBox( NULL, TEXT("Is Digit"), NULL, NULL );
}
cstring转为int}
函数 isdigit 返回值为0代表字符串存在,相反不为0代表数字。