How do I convert a std::string
to an uint64_t
? I would also like the function to throw if the string does not contain a pure representation of an uint64_t
. For example, conversions of these should throw:
"NO: 9889"
"9889L"
"9889U"
"1e+22"
or indicate by another means that they are not a pure representation. I am using C++98 and boost (including boost::regex
).
Use boost::lexical_cast
. It will throw a bad_lexical_cast
if the number can't be parsed or overflows.
If you ever switch to C++11, there's a new function in the standard for that which should be faster.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With