std::strtoimax, std::strtoumax

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

# 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";
}

# See also