📜  C / C++中的iswgraph()及其示例

📅  最后修改于: 2021-05-30 14:22:31             🧑  作者: Mango

iswgraph()是C / C++中的内置函数,用于检查给定的宽字符是否具有图形表示。它在C++的cwctype头文件中定义。默认情况下,以下字符是图形:

  • 数字(0到9)
  • 大写字母(A到Z)
  • 小写字母(a到z)
  • 字符(!”#$%&’()* +,-./:;?@[\]^_`{|}~)

语法

int iswgraph(ch)

参数:该函数接受一个强制性参数ch ,该参数指定宽字符,我们必须检查该宽字符是否具有图形表示形式。

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

  • 如果ch具有图形表示字符,则返回非零值。
  • 如果不是图形表示字符,则返回0。

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

程序1

// C++ program to illustrate
// iswgraph() function
#include 
#include 
using namespace std;
  
int main()
{
  
    wchar_t ch1 = '?';
    wchar_t ch2 = ' ';
  
    // Function to check if the character
    // has a graphical representation or not
    if (iswgraph(ch1))
        wcout << ch1 << " has graphical representation ";
    else
        wcout << ch1 << " does not have graphical representation ";
    wcout << endl;
  
    if (iswgraph(ch2))
        wcout << ch2 << " has graphical representation ";
    else
        wcout << ch2 << " does not have graphical representation ";
  
    return 0;
}
输出:
? has graphical representation 
  does not have graphical representation

程序2

// C++ program to illustrate
// iswgraph() function
#include 
#include 
using namespace std;
  
int main()
{
  
    wchar_t ch1 = ' ';
    wchar_t ch2 = '3';
  
    // Function to check if the character
    // has a graphical representation or not
    if (iswgraph(ch1))
        wcout << ch1 << " has graphical representation ";
    else
        wcout << ch1 << " does not have graphical representation ";
    wcout << endl;
  
    if (iswgraph(ch2))
        wcout << ch2 << " has graphical representation ";
    else
        wcout << ch2 << " does not have graphical representation ";
  
    return 0;
}
输出:
does not have graphical representation 
3 has graphical representation
想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。