ฟังก์ชัน isprint() เป็นฟังก์ชันที่กำหนดไว้ล่วงหน้า และจะตรวจสอบว่าอักขระที่ส่งผ่านนั้นพิมพ์ได้หรือไม่ ส่งกลับค่าที่ไม่ใช่ศูนย์ หากสำเร็จ มิฉะนั้นจะเป็นศูนย์ ฟังก์ชันนี้ประกาศในไฟล์ส่วนหัว “cctype”
นี่คือไวยากรณ์ของ isprint() ในภาษา C++
int isprint(int character);
ที่นี่
ตัวละคร − ตัวละครจะถูกตรวจสอบ
นี่คือตัวอย่าง isprint() ในภาษา C++
ตัวอย่าง
#include<iostream>
#include<cctype>
using namespace std;
int main() {
int val1 = 28;
int val2 = 's';
int val3 = '\n';
if(isprint(val1))
cout << "value is printable"<< endl;
else
cout << "value is not printable"<< endl;
if(isprint(val2))
cout << "value is printable"<< endl;
else
cout << "value is not printable"<< endl;
if(isprint(val3))
cout << "value is printable"<< endl;
else
cout << "value is not printable"<< endl;
return 0;
} ผลลัพธ์
value is not printable value is printable value is not printable
ในโปรแกรมข้างต้น มีการประกาศตัวแปรสามตัวเป็น val1, val2 และ val3 ตัวแปรแต่ละตัวถูกตรวจสอบว่าตัวแปรพิมพ์ได้หรือไม่
if(isprint(val1)) cout << "value is printable"<< endl; else cout << "value is not printable"<< endl; if(isprint(val2)) cout << "value is printable"<< endl; else cout << "value is not printable"<< endl; if(isprint(val3)) cout << "value is printable"<< endl; else cout << "value is not printable"<< endl;