當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


C++ iswgraph()用法及代碼示例


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 <cwctype> 
#include <iostream> 
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 <cwctype> 
#include <iostream> 
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


相關用法


注:本文由純淨天空篩選整理自IshwarGupta大神的英文原創作品 iswgraph() in C/C++ with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。