我在字符串中有一个短整数。例如:“123456”。有没有API可以检查字符串是否包含unsigned short范围内的有效数字?
谢谢!
最佳答案
只需使用流操作符输入数字:
istringstream istr("12346");
short s;
if ((istr >> s) and istr.eof())
cout << "valid: " << s << endl;
else
cout << "invalid" << endl;
(需要 header sstream
。)
关于c++ - 在短范围内验证字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5834439/