std::isalpha(std::locale)
来自 cppreference.cn
| 定义于头文件 <locale> |
||
| template< class CharT > bool isalpha( CharT ch, const locale& loc ); |
||
检查给定字符是否被给定 locale 的 std::ctype facet 分类为字母字符。
目录 |
[编辑] 参数
| ch | - | 字符 |
| loc | - | locale |
[编辑] 返回值
如果字符被分类为字母,则返回 true,否则返回 false。
[编辑] 可能实现
template<class CharT> bool isalpha(CharT ch, const std::locale& loc) { return std::use_facet<std::ctype<CharT>>(loc).is(std::ctype_base::alpha, ch); } |
[编辑] 示例
演示在不同 locale(操作系统特定)下使用 isalpha()。
运行此代码
#include <iostream> #include <locale> int main() { const wchar_t c = L'\u042f'; // cyrillic capital letter ya std::locale loc1("C"); std::cout << "isalpha('Я', C locale) returned " << std::boolalpha << std::isalpha(c, loc1) << '\n'; std::locale loc2("en_US.UTF8"); std::cout << "isalpha('Я', Unicode locale) returned " << std::boolalpha << std::isalpha(c, loc2) << '\n'; }
可能的输出
isalpha('Я', C locale) returned false
isalpha('Я', Unicode locale) returned true[编辑] 参阅
| 检查字符是否为字母 (函数) | |
| 检查宽字符是否为字母 (函数) |