Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C++

ฟังก์ชัน iswgraph() ใน C/C++

ในบทความนี้ เราจะพูดถึงการทำงาน ไวยากรณ์ และตัวอย่างของฟังก์ชัน iswgraph() ใน C++ STL

iswgraph() เป็นฟังก์ชันใน header <cwctype> ใช้ตรวจสอบว่าตัวอักษรกว้าง (wide character) ที่กำหนดมีการแสดงผลทางกราฟิก (graphical representation) หรือไม่ เป็นเวอร์ชัน wide character ของ isgraph() ใน <cctype>

ตัวอักษรกว้างใดมี graphical representation?

ตัวอักษรกว้างทุกตัวที่พิมพ์บนหน้าจอได้ มี graphical representation ยกเว้น escape characters

ไวยากรณ์

int iswgraph(ch);

พารามิเตอร์

ฟังก์ชันรับพารามิเตอร์ 1 ตัว คือ ch ชนิด wide character

ค่าที่คืน

คืนค่า integer: 0 หากไม่มี graphical representation, ค่าอื่นจาก 0 หากมี

ตัวอย่าง

Input: iswgraph('?'); Output: It has a graphical representation.
Input: iswgraph(' '); Output: It doesn't have a graphical representation.

ตัวอย่างโค้ด 1

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

int main() {
    wchar_t ch_1 = '%';
    wchar_t ch_2 = ')';
    if(iswgraph(ch_1))
        wcout << "It has graphical representation: " << ch_1;
    else
        wcout << "It doesn't have graphical representation: " << ch_1;
    if(iswgraph(ch_2))
        wcout << "\nIt has graphical representation: " << ch_2;
    else
        wcout << "\nIt doesn't have graphical representation: " << ch_2;
    return 0;
}

เอาต์พุต

It has graphical representation: %
It has graphical representation: )

ตัวอย่างโค้ด 2

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

int main() {
    wchar_t ch_1 = '9';
    wchar_t ch_2 = '\n';
    if(iswgraph(ch_1))
        wcout << "It has graphical representation: " << ch_1;
    else
        wcout << "It doesn't have graphical representation: " << ch_1;
    if(iswgraph(ch_2))
        wcout << "\nIt has graphical representation: " << ch_2;
    else
        wcout << "\nIt doesn't have graphical representation: " << ch_2;
    return 0;
}

เอาต์พุต

It has graphical representation: 9
It doesn't have graphical representation: