เราได้รับมอบหมายให้แสดงการทำงานของ iswprint( ) ฟังก์ชัน iswprint( ) ใน C++ STL ใช้เพื่อตรวจสอบว่าอักขระแบบกว้างที่ระบุสามารถพิมพ์ได้หรือไม่ เป็นฟังก์ชันที่มีอยู่ในไฟล์ส่วนหัว cwctype ใน C ++ อักขระแบบกว้างคือประเภทข้อมูลอักขระคอมพิวเตอร์ที่โดยทั่วไปแล้วจะมีขนาดใหญ่กว่าอักขระ 8 บิตแบบเดิม
ไวยากรณ์
int iswprint(c);
พารามิเตอร์
c – เป็นพารามิเตอร์ที่ระบุตัวอักษรกว้างที่ต้องตรวจสอบว่าสามารถพิมพ์ได้หรือไม่
ผลตอบแทนที่ได้รับ
ฟังก์ชันนี้จะคืนค่าที่ไม่ใช่ศูนย์หากสามารถพิมพ์ c ได้ มันจะคืนค่าศูนย์หากไม่สามารถพิมพ์ c ได้
สามารถพิมพ์อักขระต่อไปนี้ได้ −
-
ตัวพิมพ์ใหญ่ − A - Z
-
ตัวพิมพ์เล็ก − a - z
-
ตัวเลข − 0 - 9
-
เครื่องหมายวรรคตอน − ! ” @ # $ % ^ &* ( ) } | \ ] [ _ - + ’ ? / . , } :; ~ `
-
อวกาศ − ……
-
ไม่เสถียรหรือไม่
ตัวอย่าง
#include <cwchar.h>
#include<iostream.h>
#inlude<cwctype.h>
Using namespace std;
int main( ){
wchar_t str[ ] = “ authorized<channel<partners”;
wcout<<str;
for( int i = 0; i < wcslen(str); i++){
if ( !iswprint(str[i]))
str[i] = ‘ @ ’;
}
wcout<<str;
return 0;
} ผลลัพธ์
หากเรารันโค้ดด้านบน มันจะสร้างผลลัพธ์ต่อไปนี้
authorized<channel<partners authorised@channel@partners
ตัวอย่าง
#include <cwchar.h>
#include<iostream.h>
#inlude<cwctype.h>
Using namespace std;
int main( ){
wchar_t str[ ] = “ and I am<= Iron Man”;
wcout<<str;
for( int i = 0; i < wcslen(str); i++){
if ( !iswprint(str[i]))
str[i] = ‘ & ’;
}
wcout<<str;
return 0;
} ผลลัพธ์
ถ้าเรารันโค้ดด้านบน มันจะสร้างผลลัพธ์ต่อไปนี้
and I am<= Iron Man and I am &&Iron Man