ในบทความนี้ เราจะพูดถึงการทำงาน ไวยากรณ์ และตัวอย่างของฟังก์ชัน iswgraph() ใน C++ STL
iswgraph() เป็นฟังก์ชันที่อยู่ภายใต้ไฟล์ส่วนหัว
อักขระกว้างใดบ้างที่มีการแสดงแบบกราฟิก
อักขระกว้างทั้งหมดที่สามารถพิมพ์บนหน้าจอได้คืออักขระที่มีการแสดงภาพกราฟิก ยกเว้นอักขระหลีกคืออักขระที่มีการแสดงแบบกราฟิก
ไวยากรณ์
int iswgraph(ch);
พารามิเตอร์
ฟังก์ชันยอมรับพารามิเตอร์เพียงตัวเดียวคือ ch ซึ่งเป็นประเภทอักขระแบบกว้าง
คืนค่า
ส่งคืนค่าจำนวนเต็มเช่น 0 คืออักขระแบบกว้างไม่ได้แสดงแบบกราฟิกและค่าที่ไม่ใช่ศูนย์หากอักขระแบบกว้างถูกแสดงแบบกราฟิก
ตัวอย่าง
Input: iswgraph(‘?’); Output: It has a graphical representation. Input: iswgraph(‘ ’); Output: It doesn’t have a graphical representation.
ตัวอย่าง
#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: )
ตัวอย่าง
#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: ?