If you can use a modern compiler or Boost, then lexical_cast
will do the job:
uint64_t bigint;
try {
bigint = lexical_cast<uint64_t>(str);
} catch (std::bad_lexical_cast &e) {
// do whatever you want to do when the string isn't valid;
}
// Safely use bigint
See this link for the Boost library. You can definitely get this for VS 2008.
If this is Windows only you can also look at _atoi64
and the like. See msdn. These return I64_MAX
and I64_MIN
in case of over/underflow.