该函数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;