I am using visual studio 2012 and strtoull is undefined while strtoul works OK. I have included
#include <stdio.h>
#include <stdlib.h>
But strtoull is still undefined.
Some versions of MSVC don't have a strtoull function.
You can try using _strtoui64.
Edit:
Like mentioned in the comments you can also try switching to C++11 if it is available to you.
Another way to handle it (that is portable, does not require Boost, and works in C++03):
std::string s = SOME_NUMER_IN_A_STRING_FORMAT;
unsigned long myValue = 0;
std::istringstream iss(s);
if (!(iss >> myValue))
{
// error parsing number
}
else
{
// myValue successfully parsed
}
Note that if you want a 64-bit integer in a pre-C++11 compiler, you'll have to use a compiler-specific type (which may not have an overload for stream operations).
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