std::strtoul, std::strtoull
Min standard notice:
Header: <cstdlib>
Interprets an unsigned integer value in a byte string pointed to by str.
# Declarations
unsigned long strtoul ( const char* str, char** str_end, int base );
unsigned long long strtoull( const char* str, char** str_end, int base );
(since C++11)
# Parameters
str: pointer to the null-terminated byte string to be interpretedstr_end: pointer to a pointer to character, might be set to a position past the last character interpretedbase: base of the interpreted integer value
# Return value
Integer value corresponding to the contents of str on success. If the converted value falls out of range of corresponding return type, range error occurs (errno is set to ERANGE) and ULONG_MAX or ULLONG_MAX is returned. If no conversion can be performed, 0 is returned.
# Example
#include <cstdlib>
#include <errno.h>
#include <iostream>
#include <string>
int main()
{
const char* p = "10 200000000000000000000000000000 30 -40 - 42";
char* end = nullptr;
std::cout << "Parsing '" << p << "':\n";
for (unsigned long i = std::strtoul(p, &end, 10);
p != end;
i = std::strtoul(p, &end, 10))
{
std::cout << "'" << std::string(p, end - p) << "' -> ";
p = end;
if (errno == ERANGE)
{
errno = 0;
std::cout << "range error, got ";
}
std::cout << i << '\n';
}
std::cout << "After the loop p points to '" << p << "'\n";
}