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 );
}
}

转自:http://zhidao.baidu.com/question/56928981.html?an=0&si=1

函数 isdigit 返回值为0代表字符串存在,相反不为0代表数字。

posted @ 2012-03-16 12:14  stma  阅读(4508)  评论(0)    收藏  举报