wcstoul, wcstoull
|
定义于头文件
<wchar.h>
|
||
|
unsigned
long
wcstoul
(
const
wchar_t
*
str,
wchar_t
**
str_end,
int
base
)
;
|
(C95 起)
(C99 前) |
|
|
unsigned
long
wcstoul
(
const
wchar_t
*
restrict
str,
wchar_t ** restrict str_end, int base ) ; |
(C99 起) | |
|
unsigned
long
long
wcstoull
(
const
wchar_t
*
restrict
str,
wchar_t ** restrict str_end, int base ) ; |
(C99 起) | |
将
str
所指向的宽字符串解析为无符号整数值。
丢弃所有空白字符(通过调用
iswspace
识别),直到找到第一个非空白字符,然后尽可能多地提取字符以构成有效的
base-n
(其中n=
base
)无符号整数表示形式,并将其转换为整数值。有效的无符号整数值由以下部分组成:
- (可选) 正负号
-
(可选)
前缀 (
0) 表示八进制基数(仅当基数为 8 或 0 时适用) -
(可选)
前缀 (
0x或0X) 表示十六进制基数(仅当基数为 16 或 0 时适用) - 数字序列
基数的有效取值范围为
{0, 2, 3, ..., 36}
。对于基数为
2
的整数,有效数字集为
{0, 1}
;对于基数为
3
的整数,有效数字集为
{0, 1, 2}
,依此类推。对于大于
10
的基数,有效数字包含字母字符:从基数为
11
的整数使用
Aa
开始,到基数为
36
的整数使用
Zz
结束。字符的大小写将被忽略。
当前安装的 C locale 可能接受其他数字格式。
如果
base
的值为
0
,将自动检测数值进制:若前缀为
0
则为八进制,若前缀为
0x
或
0X
则为十六进制,否则为十进制。
如果减号是输入序列的一部分,则从数字序列计算出的数值将被取反,如同通过结果类型中的 一元减号 操作,该操作遵循无符号整数回绕规则。
该函数设置由
str_end
指向的指针,使其指向最后一个被解释的宽字符之后的位置。如果
str_end
是空指针,则忽略该参数。
目录 |
参数
| str | - | 指向待解析的空终止宽字符串的指针 |
| str_end | - | 指向宽字符指针的指针 |
| base | - | base 被解析整数值的基数 |
返回值
成功时返回与
str
内容对应的整数值。若转换值超出对应返回类型的范围,将发生范围错误并返回
ULONG_MAX
或
ULLONG_MAX
。若无法执行任何转换,则返回
0
。
示例
#include <stdio.h> #include <errno.h> #include <wchar.h> int main(void) { const wchar_t *p = L"10 200000000000000000000000000000 30 40"; printf("Parsing L'%ls':\n", p); wchar_t *end; for (unsigned long i = wcstoul(p, &end, 10); p != end; i = wcstoul(p, &end, 10)) { printf("'%.*ls' -> ", (int)(end-p), p); p = end; if (errno == ERANGE){ printf("range error, got "); errno = 0; } printf("%lu\n", i); } }
输出:
Parsing '10 200000000000000000000000000000 30 40': '10' -> 10 ' 200000000000000000000000000000' -> range error, got 18446744073709551615 ' 30' -> 30 ' 40' -> 40
参考文献
- C11 标准 (ISO/IEC 9899:2011):
-
- 7.29.4.1.2 wcstol、wcstoll、wcstoul 和 wcstoull 函数 (第 429-430 页)
- C99 标准 (ISO/IEC 9899:1999):
-
- 7.24.4.1.2 wcstol、wcstoll、wcstoul 和 wcstoull 函数 (第 375-376 页)
参考
|
(C99)
|
将字节字符串转换为无符号整数值
(函数) |
|
(C95)
(C99)
|
将宽字符串转换为整数值
(函数) |
|
C++ 文档
for
wcstoul
,
wcstoull
|
|