Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ strtoull function undefined?

Tags:

c++

visual-c++

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.

like image 438
Luka Avatar asked Dec 06 '25 02:12

Luka


2 Answers

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.

like image 200
OlivierLi Avatar answered Dec 08 '25 15:12

OlivierLi


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).

like image 44
Zac Howland Avatar answered Dec 08 '25 15:12

Zac Howland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!