[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/string/byte/strtoimax [Back]  [Original]

std::strtoimax, std::strtoumax cppreference.com
cppreference.com

std::strtoimax, std::strtoumax

cppreference.com

<metanoindex/>

<tbody> </tbody>
std::intmax_t strtoimax(const char* nptr, char** endptr, int base);
( C++11)
std::uintmax_t strtoumax(const char* nptr, char** endptr, int base);
( C++11)
, nptr.
:
Interprets an integer value in a byte string pointed to by nptr.
Google.
. .

( std::isspace) , , -n ( n=base) . :

  • ()
  • () (0), (, 8 0)
  • () (0x 0X), (, 16 0)
  • .

{0,2,3,...,36}. 2 {0,1}, 3 {0,1,2}, . , 10, , Aa 11, Zz 36. .

C.

base 0, : 0, , 0x 0X, , .

, , , , .

endptr . endptr NULL, .
:
The functions sets the pointer pointed to by endptr to point to the character past the last character interpreted. If endptr is NULL, it is ignored.
Google.
. .
nptr , , ( enptr NULL) nptr , endptr.
:
If the nptr is empty or does not have the expected form, no conversion is performed, and (if enptr is not NULL) the value of nptr is stored in the object pointed to by endptr.
Google.
. .

nptr
:
pointer to the null-terminated byte string to be interpreted
Google.
. .
endptr
.
:
pointer to a pointer to character.
Google.
. .
base
'
:
base of the interpreted integer value
Google.
. .

#include <iostream>
#include <string>
#include <cinttypes>

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';
}

:

helloworld in base 36 is 1767707668033969 in base 10
helloworld in base 30 is invalid. The first invalid digit is w

.

(C++11)(C++11)
std::intmax_t std::uintmax_t
() []

() []

() []
C strtoimax, strtoumax

Web Proxy Viewer  |  New URL  |  Original Page