I don't know why stoi exists, but not stou , but the only difference between stoul and a hypothetical stou will be to verify that the result is in the unsigned range:
unsigned stou(std::string const & str, size_t * idx = 0, int base = 10) { unsigned long result = std::stoul(str, idx, base); if (result > std::numeric_limits<unsigned>::max()) { throw std::out_of_range("stou"); } return result; }
(Similarly, stoi also similar to stol , just with a different range check, but since it already exists, there is no need to worry about how to implement it.)
Mike Seymour Jan 03 '12 at 17:05 2012-01-03 17:05
source share