std::wcstoimax, std::wcstoumax

Header: <cinttypes>

Interprets an unsigned integer value in a wide string pointed to by nptr.

# Declarations

std::intmax_t wcstoimax( const wchar_t* nptr, wchar_t** endptr, int base );

(since C++11)

std::uintmax_t wcstoumax( const wchar_t* nptr, wchar_t** endptr, int base );

(since C++11)

# Parameters

# 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 and INTMAX_MAX, INTMAX_MIN, UINTMAX_MAX, or 0 is returned, as appropriate. If no conversion can be performed, 0 is returned.

# Example

#include <cinttypes>
#include <iostream>
#include <string>
 
int main()
{
    std::wstring str = L"helloworld";
    std::intmax_t val = std::wcstoimax(str.c_str(), nullptr, 36);
    std::wcout << str << " in base 36 is " << val << " in base 10\n";
 
    wchar_t* nptr;
    val = std::wcstoimax(str.c_str(), &nptr, 30);
    if (nptr != &str[0] + str.size())
        std::wcout << str << " in base 30 is invalid."
                   << " The first invalid digit is " << *nptr << '\n';
}

# See also