验证短范围内的字符串

编程入门 行业动态 更新时间:2024-10-25 19:34:44
本文介绍了验证短范围内的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在字符串中有一个短整数。例如: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.)

更多推荐

验证短范围内的字符串

本文发布于:2023-11-09 23:07:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573688.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:范围内   字符串

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!