C++ 中的wctype() 函数返回用于宽字符分类的 wctype_t 类型的值。
wctype() 函数在<cwctype> 头文件中定义。
wctype()原型
wctype_t wctype(const char* str);
wctype() 函数将 C 字符串 str
作为其参数,并返回用于对宽字符进行分类的 wctype_t 类型的值。
参数:
str
:指定所需类别的 C 字符串。
str 的值 | 等效函数 |
---|---|
alnum | iswalnum |
alpha | iswalpha |
blank | iswblank |
cntrl | iswcntrl |
digit | iswdigit |
graph | iswgraph |
lower | iswlower |
iswprint | |
punct | iswpunct |
space | iswspace |
xdigit | iswxdigit |
upper | iswupper |
返回:
- wctype() 函数返回一个 wctype_t 对象,该对象可与 towctype() 一起使用以检查宽字符的属性。
- 如果 str 不提供当前 C 语言环境支持的类别,则返回零。
示例:wctype() 函数如何工作?
#include <cwctype>
#include <iostream>
#include <clocale>
using namespace std;
int main()
{
setlocale(LC_ALL, "en_US.UTF-8");
wchar_t wc = L'\u00b5';
if (iswctype(wc, wctype("digit")))
wcout << wc << L" is a digit";
else if (iswctype(wc, wctype("alpha")))
wcout << wc << L" is an alphabet";
else
wcout << wc << L" is neither an alphabet nor a digit";
return 0;
}
运行程序时,输出将是:
µ is an alphabet
相关用法
- C++ wctype()用法及代码示例
- C++ wctrans()用法及代码示例
- C++ wctob()用法及代码示例
- C++ wctomb()用法及代码示例
- C++ wcstold()用法及代码示例
- C++ wcerr用法及代码示例
- C++ wcsftime()用法及代码示例
- C++ wcstod()用法及代码示例
- C++ wcscspn()用法及代码示例
- C++ wcsncmp()用法及代码示例
- C++ wcin用法及代码示例
- C++ wcstok()用法及代码示例
- C++ wcsstr()用法及代码示例
- C++ wcsrchr()用法及代码示例
- C++ wcsncpy()用法及代码示例
- C++ wcslen()用法及代码示例
- C++ wcsspn()用法及代码示例
- C++ wclog用法及代码示例
- C++ wcschr()用法及代码示例
- C++ wcstof()用法及代码示例
注:本文由纯净天空筛选整理自 C++ wctype()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。