Iswspace Function In Cc++ - C++ Programming Tutorial
C++ Course / Functions / Iswspace Function In Cc++

Iswspace Function In Cc++

BLUF: Mastering Iswspace Function In Cc++ is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Iswspace Function In Cc++

C++ is renowned for its efficiency. Learn how Iswspace Function In Cc++ enables low-level control and high-performance computing in the tutorial below.

In this guide, we will discuss the syntax, functionality, and output of the C++ iswspace function.

What is the iswspace function?

The C++ standard library's iswspace function is declared in the <cwctype> header file. This function checks if the given wide character is a whitespace character, behaving similarly to the isspace function but for wide characters. When the input character is a whitespace character, the function evaluates it as true and outputs a non-zero integer; otherwise, it returns zero to indicate false.

Syntax:

It has the following syntax:

Example

int iswspace(wint_t ch);

Parameters:

The function requires a single mandatory parameter, ch, representing the wide character to be examined for the presence of a wide whitespace character. This argument is converted into either WEOF or wintt. The wintt type is used to hold integral data.

Value returned

If the function results in a false outcome, it will yield a value of zero; conversely, when it returns true, it will provide any non-zero value.

The preceding function is illustrated by the programs following.

Program 1:

Example

// C++ program to illustrate
// iswspace() function
#include <cwctype>
#include <iostream>
using namespace std;

int main()
{
 wchar_t c;
 int i = 0;
 wchar_t str[] = L"Welcome to Cpp Tutorial - Learn C++ Programming\n";

 // Check for every character
 // in the string
 while (str[i]) {
 c = str[i];

 // Function to check if the character
 // is a wide whitespace or not
 if (iswspace(c))
 c = L'\n';
 putwchar(c);
 i++;
 }
 return 0;
}

Output:

Output

Welcome
to
Cpp Tutorial
-
Learn
C++
Programming

Program 2:

Example

// C++ program to illustrate
// iswspace() function
#include <cwctype>
#include <iostream>
using namespace std;

int main()
{
 wchar_t c;
 int i = 0;
 wchar_t str[] = L"This is a small example.\n";

 // Check for every character
 // in the string
 while (str[i]) {
 c = str[i];
 // Function to check if the character
 // is a wide whitespace or not
 if (iswspace(c))
 c = L'\n';
 putwchar(c);
 i++;
 }
 return 0;
}

Output:

Output

This
is
a
small
example.

Conclusion:

In summary, determining if a wide character is a white-space character can be achieved effortlessly by employing the iswspace function in C/C++. When dealing with extensive character sets, programmers can enhance the adaptability and compatibility of their code by leveraging this technique from the <cwctype> header.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience