📅  最后修改于: 2023-12-03 14:39:49.943000             🧑  作者: Mango
iswalnum()
是 C++ 的标准库函数之一,用于检查给定的宽字符是否是字母或数字。它返回非零值,如果参数是宽字符,否则返回零。
#include <cwctype>
wctype_t iswalnum(wint_t wc);
其中 wint_t
是一个宽字符类型,wctype_t
是一个整数类型。
wc
:要检查的宽字符。
如果 wc
是字母或数字,返回非零值,否则返回零。
#include <iostream>
#include <cwctype>
int main() {
std::wstring str = L"Hello, world! 2022";
for (wchar_t c : str) {
if (iswalnum(c)) {
std::wcout << c << L" is a letter or digit." << std::endl;
} else {
std::wcout << c << L" is not a letter or digit." << std::endl;
}
}
return 0;
}
输出:
H is a letter or digit.
e is a letter or digit.
l is a letter or digit.
l is a letter or digit.
o is a letter or digit.
, is not a letter or digit.
is not a letter or digit.
w is a letter or digit.
o is a letter or digit.
r is a letter or digit.
l is a letter or digit.
d is a letter or digit.
! is not a letter or digit.
is not a letter or digit.
2 is a letter or digit.
0 is a letter or digit.
2 is a letter or digit.
2 is a letter or digit.
isalnum()
函数。