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


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

C++ 中的iswgraph() 函數檢查給定的寬字符是否具有圖形表示。

iswgraph() 函數在<cwctype> 頭文件中定義。

iswgraph()原型

int iswgraph(wint_t ch);

iswgraph() 函數檢查 ch 是否具有按當前 C 語言環境分類的圖形表示。默認情況下,以下字符是圖形:

  • 數字(0 到 9)
  • 大寫字母(A 到 Z)
  • 小寫字母(a 到 z)
  • 標點符號(!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)

參數:

  • ch :要檢查的寬字符。

返回:

  • 如果ch 具有圖形表示字符,則iswgraph() 函數返回非零值。
  • 如果ch 沒有圖形表示字符,則返回零。

示例:iswgraph() 函數如何工作?

#include <cwctype>
#include <iostream>
#include <clocale>
using namespace std;

int main()
{
	setlocale(LC_ALL, "en_US.UTF-8");
	wchar_t ch1 = L'\u0009';
	wchar_t ch2 = L'\u03a9';
	
	iswgraph(ch1)? wcout << ch1 << L" has graphical representation" : wcout << ch1 << L" does not have graphical representation";
	wcout << endl;
	iswgraph(ch2)? wcout << ch2 << L" has graphical representation" : wcout << ch2 << L" does not have graphical representation";

	return 0;
}

運行程序時,輸出將是:

 	 does not have graphical representation
Ω has graphical representation

相關用法


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