std::strtoimax, std::strtoumax
Min standard notice:
Header: <cinttypes>
Interprets an integer value in a byte string pointed to by nptr.
# Declarations
std::intmax_t strtoimax( const char* nptr, char** endptr, int base );
(since C++11)
std::uintmax_t strtoumax( const char* nptr, char** endptr, int base );
(since C++11)
# Parameters
nptr: pointer to the null-terminated byte string to be interpretedendptr: pointer to a pointer to character.base: base of the interpreted integer value
# Example
#include <cinttypes>
#include <iostream>
#include <string>
int main()
{
std::string str = "helloworld";
std::intmax_t val = std::strtoimax(str.c_str(), nullptr, 36);
std::cout << str << " in base 36 is " << val << " in base 10\n";
char* nptr;
val = std::strtoimax(str.c_str(), &nptr, 30);
if (nptr != &str[0] + str.size())
std::cout << str << " in base 30 is invalid."
<< " The first invalid digit is '" << *nptr << "'\n";
}