c++ - Validate string within short range -
i have short integer in string. eg: "123456". there api check whether string contains valid number in range of unsigned short?
thanks!
simply use stream operators input number:
istringstream istr("12346"); short s; if ((istr >> s) , istr.eof()) cout << "valid: " << s << endl; else cout << "invalid" << endl;
(needs header sstream
.)
Comments
Post a Comment