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!
I'm fond of boost::lexical_cast :
#include <boost/lexical_cast.hpp>
#include <iostream>
#include <string>
int main() {
std::string s("12346");
try {
boost::lexical_cast<unsigned short>(s);
std::cout << "valid\n";
} catch (boost::bad_lexical_cast&) {
std::cout << "invalid\n";
}
}
long) and using the comparision operators... - user395760errno=0; strtoul( str, 0, 10 ) <= USHRT_MAX && !errno? - Marc Mutz - mmutz