本文介绍了验证短范围内的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在字符串中有一个短整数。例如:123456。是否有任何API检查字符串是否包含无符号短整数范围内的有效数字?
谢谢!
istringstream istr( 12346); short s; if((istr>> s)和istr.eof()) cout< valid:<< s<< endl; else cout<< invalid<< endl;(需要标题 sstream 。)
I have a short integer in a string. For Eg: "123456". Is there any API to check whether the string contains a valid number in the range of unsigned short?
Thanks!
解决方案Simply use the stream operators to input the number:
istringstream istr("12346"); short s; if ((istr >> s) and istr.eof()) cout << "valid: " << s << endl; else cout << "invalid" << endl;(Needs the header sstream.)
更多推荐
验证短范围内的字符串
发布评论