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


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


iswprint()是C /C++中的內置函數,該函數檢查是否可以打印給定的寬字符。它在C++的cwctype頭文件中定義。默認情況下,以下字符是可打印的:

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

用法

int iswprint(ch)

參數:該函數接受單個強製性參數ch,該參數指定必須檢查的寬字符(是否可打印)。


返回值:該函數返回兩個值,如下所示。

  • 如果參數ch是可打印的,則返回非零值。
  • 如果不是可打印字符,則返回0。

以下示例程序旨在說明上述函數。

程序1

// Program to illustrate 
// towprint() function 
#include <cwchar> 
#include <cwctype> 
#include <iostream> 
using namespace std; 
int main() 
{ 
  
    wchar_t str[] = L"Geeks\tfor\tGeeks"; 
    for (int i = 0; i < wcslen(str); i++) { 
  
        // Function to check if the characters are 
        // printable or not. If not, then replace 
        // all non printable character by comma 
        if (!iswprint(str[i])) 
            str[i] = ', '; 
    } 
    wcout << "Printing, if the given wide  
    character cannot be printed\n"; 
    wcout << str; 
    return 0; 
}
輸出:
Printing , if the given wide character cannot be printed
Geeks, for, Geeks

程序2

// Program to illustrate 
// towprint() function 
#include <cwchar> 
#include <cwctype> 
#include <iostream> 
using namespace std; 
int main() 
{ 
  
    wchar_t str[] = L"Ishwar Gupta\t123\t!@#"; 
    for (int i = 0; i < wcslen(str); i++) { 
  
        // Function to check if the characters are 
        // printable or not. If not, then replace 
        // all non printable character by comma 
        if (!iswprint(str[i])) 
            str[i] = ', '; 
    } 
    wcout << "Printing, if the given wide  
    character cannot be printed\n"; 
    wcout << str; 
    return 0; 
}
輸出:
Printing , if the given wide character cannot be printed
Ishwar Gupta, 123, !@#


相關用法


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