Hàm iswalnum() trong C++ STL kiểm tra xem ký tự rộng cho trước có phải là ký tự alphanumeric (chữ số 0-9, chữ hoa A-Z, chữ thường a-z) hay không.
Thuật toán
Begin
Khởi tạo ký tự.
Gọi hàm iswalnum(c1) kiểm tra alphanumeric.
Nếu là alphanumeric, trả về giá trị khác 0, ngược lại 0.
End
Ví dụ mã
#include <cwctype>
#include <iostream>
using namespace std;
int main() {
wchar_t c1 = '/';
wchar_t c2 = 'a';
if (iswalnum(c1))
wcout << c1 << " is alphanumeric ";
else
wcout << c1 << " is not alphanumeric ";
wcout << endl;
if (iswalnum(c2))
wcout << c2 << " is alphanumeric ";
else
wcout << c2 << " is not alphanumeric ";
return 0;
}
Kết quả
/ is not alphanumeric a is alphanumeric