iswpunct() function in C++ STL

C++Server Side ProgrammingProgramming

<p>In this article we are going to discuss the iswpunct() function in C++, its syntax, working and its return values.</p><p>iswpunct() function is an inbuilt function in C++ which is defined in &lt;cwctype&gt; header file. The function checks whether the passed wide character is a punctuation character or not. This function is a wide character equivalent of ispunct(), which means it works the same as ispunct() the difference is it supports a wide character. So, the function checks if the argument passed is punctuation character then return any non zero integer value(true), else it will return zero(false)</p><h2>Punctuation characters are as follows</h2><pre class="result notranslate">! @ # $ % ^ &amp; * ( ) &ldquo; &lsquo; , . / ; [ { } ] : ?</pre><h2>Syntax</h2><pre class="result notranslate">int iswpunct(wint_t ch);</pre><p>The function accepts only one parameter, i.e. a wide character which is to be checked. The argument is casted in wint_t or WEOF.</p><p>wint_t stores an integral type of data.</p><h2>Return value</h2><p>The function returns an integer value, which can be either 0 (in case of false) or any non-zero value(in case of true).</p><h2>Example</h2><p><a class="demo" href="http://tpcg.io/EfnRcFnS" rel="nofollow" target="_blank">&nbsp;Live Demo</a></p><pre class="prettyprint notranslate">#include &lt;iostream&gt; #include &lt;cwctype&gt; using namespace std; int main() { &nbsp; &nbsp;wint_t a = &#39;.&#39;; &nbsp; &nbsp;wint_t b = &#39;a&#39;; &nbsp; &nbsp;wint_t c = &#39;1&#39;; &nbsp; &nbsp;iswpunct(a)?cout&lt;&lt;&quot; Its Punctuation character&quot;:cout&lt;&lt;&quot; Not Punctuation character&quot;; &nbsp; &nbsp;iswpunct(b)?cout&lt;&lt;&quot; Its Punctuation character&quot;:cout&lt;&lt;&quot; Not Punctuation character&quot;; &nbsp; &nbsp;iswpunct(c)?cout&lt;&lt;&quot; Its Punctuation character&quot;:cout&lt;&lt;&quot; Not Punctuation character&quot;; }</pre><h2>Output</h2><p>If we run the above code it will generate the following output &minus;</p><pre class="result notranslate">Its Punctuation character Not Punctuation character Not Punctuation character</pre><h2>Example</h2><p><a class="demo" href="http://tpcg.io/Pj3FwBcS" rel="nofollow" target="_blank">&nbsp;Live Demo</a></p><pre class="prettyprint notranslate">#include &lt;iostream&gt; #include &lt;cwctype&gt; using namespace std; int main () { &nbsp; &nbsp;int i, count; &nbsp; &nbsp;wchar_t s[] = L&quot;@tutorials, point!!&quot;; &nbsp; &nbsp;count = i = 0; &nbsp; &nbsp;while (s[i]) { &nbsp; &nbsp; &nbsp; if(iswpunct(s[i])) &nbsp; &nbsp; &nbsp; count++; &nbsp; &nbsp; &nbsp; i++; &nbsp; &nbsp;} &nbsp; &nbsp;cout&lt;&lt;&quot;There are &quot;&lt;&lt;count &lt;&lt;&quot; punctuation characters. &quot;; &nbsp; &nbsp;return 0; }</pre><h2>Output</h2><p>If we run the above code it will generate the following output &minus;</p><pre class="result notranslate">There are 4 punctuation characters.</pre>
raja
Updated on 28-Feb-2020 06:07:18

Advertisements