Namespaces
Variants

std:: isalnum (std::locale)

From cppreference.net
定义于头文件 <locale>
template < class CharT >
bool isalnum ( CharT ch, const locale & loc ) ;

检查给定字符是否被指定区域的 std::ctype 刻面归类为字母数字字符。

目录

参数

ch - 字符
loc - 区域设置

返回值

若字符被分类为字母数字则返回 true ,否则返回 false

可能的实现

template<class CharT>
bool isalnum(CharT ch, const std::locale& loc)
{
    return std::use_facet<std::ctype<CharT>>(loc).is(std::ctype_base::alnum, ch);
}

示例

演示了在不同区域设置(操作系统特定)下使用 isalnum() 的情况。

#include <iostream>
#include <locale>
int main()
{
    const wchar_t c = L'\u2135'; // mathematical symbol aleph
    std::locale loc1("C");
    std::cout << "isalnum('ℵ', C locale) returned "
              << std::boolalpha << std::isalnum(c, loc1) << '\n';
    std::locale loc2("en_US.UTF-8");
    std::cout << "isalnum('ℵ', Unicode locale) returned "
              << std::boolalpha << std::isalnum(c, loc2) << '\n';
}

可能的输出:

isalnum('ℵ', C locale) returned false
isalnum('ℵ', Unicode locale) returned true

参见

检查字符是否为字母数字
(函数)
检查宽字符是否为字母数字
(函数)