C++ 中的 iswprint( )


我们的任务是展示 iswprint( ) 的工作机制。C++ STL 中的 iswprint( ) 函数用于检查给定宽字符是否可以打印。它是在 C++ 的 cwctype 头文件中出现的一个函数。宽字符是一种计算机字符数据类型,通常比传统的 8 位字符更大。

语法

int iswprint(c);

参数

c - 这是一项参数,它指定要检查是否可以打印的宽字符。

返回值

如果可以打印 c,此函数将返回一个非零值。如果不能打印 c,它将返回 0。

以下给定的字符是可打印的 -

  • 大写字母 - 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

更新于:2020-08-14

40 次访问

开启您的 职业生涯

完成课程以获得认证

开始
广告
© . All rights reserved.