📜  C / C++中的wctype()函数

📅  最后修改于: 2021-05-26 00:14:52             🧑  作者: Mango

wctype()是C / C++中的内置函数,它返回wctype_t类型的值,该值用于对宽字符进行分类。它在C++的cwctype头文件中定义。以下是可能的类型wctype_t:

Value of str Equivalent function
space iswspace
upper iswupper
xdigit iswxdigit
print iswprint
punct iswpunct
graph iswgraph
lower iswlower
cntrl iswcntrl
digit iswdigit
alpha iswalpha
blank iswblank
alnum iswalnum

句法:

wctype_t wctype(const char* str)

参数:该函数接受单个强制性参数str ,该参数指定所需的wctype类别。

返回值:该函数返回两个值,如下所示:

  • 该函数返回一个wctype_t对象,该对象可以与iswctype()或towctype()一起使用,以检查宽字符的属性。
  • 如果str不提供当前C语言环境支持的类别,则它返回零。

下面的程序说明了上述函数。
程序1:

#include 
using namespace std;
  
int main()
{
    wchar_t wc = L'@';
  
    // checks if the type is digit
    if (iswctype(wc, wctype("digit")))
        wcout << wc << L" is a digit";
  
    // checks if the type is alpha
    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 neither an alphabet nor a digit

输出:

@ is neither an alphabet nor a digit

程式2:

#include 
using namespace std;
  
int main()
{
    wchar_t wc = L'g';
  
    // checks if the type is digit
    if (iswctype(wc, wctype("digit")))
        wcout << wc << L" is a digit";
  
    // checks if the type is alpha
    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;
}
输出:
g is an alphabet
想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。