#include <iostream> #include <string> #include <sstream> using namespace std; bool isnum(string s) { stringstream sin(s); double t; char p; if(!(sin >> t)) return false; if(sin >> p) return false; else return true; } int main() { string s; while(cin >> s) { if(isnum(s)) cout << s << " is a number." << endl; else cout << s << " is not a number." << endl; } }
c++中怎么判断一个string类型的字符串变量是否为数字?
最新推荐文章于 2022-12-21 14:09:16 发布