bool isNum(const string& str) { bool bRet = false; bool point = false; if(str.length() == 0) { return bRet; } if (!isdigit(str[0]) && str[0] != ‘+‘ && str[0] != ‘-‘ ) { return bRet; } if (str[1] == ‘.‘ && (str[0] == ‘+‘ || str[0] == ‘-‘)) { return bRet; } for ( int i = 1; i < str.length(); i++ ) { if (!isdigit(str[i])) { if (str[i] == ‘.‘ && !point) { point = true; } else { return bRet; } } } return true; }
时间: 2024-10-28 22:59:06