c++中怎么判断一个string类型的字符串变量是否为数字
展开全部
c库<ctype.h>提供了一些函数,可以用来判断一个字符是不是数字。不过并没有提供用来判断一个字符串的函数。所以你需要自己遍历字符串,用ctype库提供的函数来判断字符串中的每一个字符。很简单事,一个循环就可以。
ctype提供的函数有:
isalnum
Check if character is alphanumeric (function )
isalpha
Check if character is alphabetic (function )
isblank
Check if character is blank (function )
iscntrl
Check if character is a control character (function )
isdigit
Check if character is decimal digit (function )
isgraph
Check if character has graphical representation (function )
islower
Check if character is lowercase letter (function )
isprint
Check if character is printable (function )
ispunct
Check if character is a punctuation character (function )
isspace
Check if character is a white-space (function )
isupper
Check if character is uppercase letter (function )
isxdigit
Check if character is hexadecimal digit (function )
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询