std::strtoimax, std::strtoumax
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <cinttypes> 中定义
|
||
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
.Function discards any whitespace characters until first non-whitespace character is found. Then it takes as many characters as possible to form a valid base-n (where n=base) integer number representation and converts them to an integer value. The valid integer value consists of the following parts:
- (可选) plus or minus sign
- (可选) prefix (
0
) indicating octal base (applies only when the base is 8) - (可选) prefix (
0x
or0X
) indicating hexadecimal base (applies only when the base is 16) - a sequence of digits
The set of valid digits for base-2 integer is 01
, for base-3 integer is 012
, and so on. For bases larger than 10
, valid digits include alphabetic characters, starting from Aa
for base-11 integer, to Zz
for base-36 integer. The case of the characters is ignored.
。的功能设置的指针所指向的
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.。如果
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
.[编辑] 。参数。
nptr | - | 。 null结尾的字节串的指针进行解释。
原文: pointer to the null-terminated byte string to be interpreted |
endptr | - | 。字符指针的指针.
|
base | - | 。 “基地”的解释的整数值。
原文: base of the interpreted integer value |
===。 返回值。===
- 。如果成功的话,一个整数值对应的内容
str
退货。.原文:If successful, an integer value corresponding to the contents ofstr
is returned. - 。如果没有可以进行转换,0返回.原文:If no conversion can be performed, 0 is returned.
[编辑] 。为例。
#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 原文: converts a wide string to std::intmax_t or std::uintmax_t (函数) |
一个字节的字符串转换为整数的值 原文: converts a byte string to an integer value (函数) | |
一个无符号整数的值转换为字节字符串 原文: converts a byte string to an unsigned integer value (函数) | |
C documentation for strtoimax, strtoumax
|