C++官网参考链接:https://cplusplus.com/reference/cwctype/wctype/
函数
wctype
wctype_t wctype (const char* property);
返回字符属性
返回一个类型为wctype_t的值,该值对应于property指定的字符类别。
特定的语言环境可以接受多个类别,用于对其字符进行分类。至少下列类别为所有语言环境所认可:
| string passed as property | description | equivalent function |
|---|---|---|
| "alnum" | alphanumerical character | iswalnum |
| "alpha" | letter character | iswalpha |
| "blank" | blank character | iswblank |
| "cntrl" | control character | iswcntrl |
| "digit" | decimal digit character | iswdigit |
| "graph" | character with graphical representation | iswgraph |
| "lower" | lowercase letter character | iswlower |
| "print" | printable character | iswprint |
| "punct" | punctuation character | iswpunct |
| "space" | white-space character | iswspace |
| "upper" | uppercase letter character | iswupper |
| "xdigit" | hexadecimal digit character | iswxdigit |
此函数返回的值取决于所选的LC_CTYPE的语言环境(locale)设置的类别。
形参
property
标识字符类别的字符串(见上面)。
返回值
类型为wctype_t的值,标识特定的字符类别。
该值与语言环境有关。
用例
/* wctype example */
#include
#include
int main ()
{
int i=0;
wchar_t str[] = L"Test String.\n";
wchar_t c;
wctype_t check = wctype("lower");
wctrans_t trans = wctrans("toupper");
while (str[i])
{
c = str[i];
if (iswctype(c,check)) c = towctrans(c,trans);
putwchar (c);
i++;
}
return 0;
}
输出:
