std:: iswdigit
From cppreference.net
|
定义于头文件
<cwctype>
|
||
|
int
iswdigit
(
wint_t ch
)
;
|
||
检查给定的宽字符在窄化后是否对应于十个十进制数字字符之一 0123456789 。
如果 ch 的值既不能表示为 wchar_t 也不等于宏 WEOF 的值,则行为是未定义的。
目录 |
参数
| ch | - | 宽字符 |
返回值
若宽字符为数字字符则返回非零值,否则返回零。
注释
std::iswdigit
和
std::iswxdigit
是仅有的不受当前安装的 C 区域设置影响的标准宽字符分类函数。
示例
某些区域设置提供检测非ASCII数字的额外字符类别
运行此代码
#include <clocale> #include <cwctype> #include <iostream> void test(wchar_t a3, wchar_t u3, wchar_t j3) { std::wcout << std::boolalpha << "\t '" << a3 << "' '" << u3 << "' '" << j3 << "'\n" << "iswdigit: " << (bool)std::iswdigit(a3) << " " << (bool)std::iswdigit(u3) << " " << (bool)std::iswdigit(j3) << '\n' << "jdigit: " << (bool)std::iswctype(a3, std::wctype("jdigit")) << ' ' << (bool)std::iswctype(u3, std::wctype("jdigit")) << ' ' << (bool)std::iswctype(j3, std::wctype("jdigit")) << '\n'; } int main() { wchar_t a3 = L'3'; // the ASCII digit 3 wchar_t u3 = L'三'; // the CJK numeral 3 wchar_t j3 = L'3'; // the full-width digit 3 std::setlocale(LC_ALL, "en_US.utf8"); std::wcout << "In American locale:\n"; test(a3, u3, j3); std::wcout << "\nIn Japanese locale:\n"; std::setlocale(LC_ALL, "ja_JP.utf8"); test(a3, u3, j3); }
可能的输出:
In American locale:
'3' '三' '3'
iswdigit: true false false
jdigit: false false false
In Japanese locale:
'3' '三' '3'
iswdigit: true false false
jdigit: false false true
参见
|
检查字符是否被本地化环境分类为数字
(函数模板) |
|
|
检查字符是否为数字
(函数) |
|
|
C 文档
关于
iswdigit
|
|
| ASCII 值 | 字符 |
isdigit
|
|||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 十进制 | 十六进制 | 八进制 | |||||||||||||
| 0–8 |
\x0
–
\x8
|
\0
–
\10
|
控制码(
NUL
等)
|
≠0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
| 9 |
\x9
|
\11
|
制表符(
\t
)
|
≠0
|
0
|
≠0
|
≠0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
| 10–13 |
\xA
–
\xD
|
\12
–
\15
|
空白字符(
\n
、
\v
、
\f
、
\r
)
|
≠0
|
0
|
≠0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
| 14–31 |
\xE
–
\x1F
|
\16
–
\37
|
控制码 |
≠0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
| 32 |
\x20
|
\40
|
空格 |
0
|
≠0
|
≠0
|
≠0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
| 33–47 |
\x21
–
\x2F
|
\41
–
\57
|
!"#$%&'()*+,-./
|
0
|
≠0
|
0
</
|
|||||||||