std::strtoimax, std::strtoumax
cppreference.com
[] |
Google. . , . , . |
<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. ( std::isspace) , , -n ( n=base) . :
- ()
- () (
0), (,80) - () (
0x0X), (,160) - .
{0,2,3,...,36}. 2 {0,1}, 3 {0,1,2}, . , 10, , Aa 11, Zz 36. .
base 0, : 0, , 0x 0X, , .
| nptr | ||
| endptr | .
| |
| base | '
|
- , ,
str. - , ( [[cpp/error/errno|errno]] ERANGE) INTMAX_MAX, INTMAX_MIN, UINTMAX_MAX
0, .:If the converted value falls out of range of corresponding return type, a range error occurs (setting [[cpp/error/errno|errno]] to ERANGE) and INTMAX_MAX, INTMAX_MIN, UINTMAX_MAX or0is returned, as appropriate. - ,
0.
#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++11) |
() |
(C++11) |
() |
C strtoimax, strtoumax
| |