Bitset all() function in C++ STL

C++Server Side ProgrammingProgramming

<p>The bitset all() function an inbuilt function of the C++ STL( Standard Template Library). This function returns a Boolean value. The returned value is true if all the bits of the calling bitset are 1 else it will return false.</p><p>The function does not accept any parameter and returns a Boolean value.</p><h2>Syntax</h2><pre class="result notranslate">Bool bitset_name .all()</pre><h2>Sample</h2><pre class="result notranslate">Bitset = 100101</pre><h2>Output</h2><pre class="result notranslate">false</pre><p>Because all bits of the set need to be true in order to return a true value.</p><h2>Example</h2><pre class="prettyprint notranslate">#include &lt;bits/stdc++.h&gt; using namespace std; void printer(bool val){ &nbsp; &nbsp;if(val){ &nbsp; &nbsp; &nbsp; cout&lt;&lt; &quot;The bitset has all bits set&quot;&lt;&lt; endl; &nbsp; &nbsp;} else{ &nbsp; &nbsp; &nbsp; cout &lt;&lt; &quot;The bitset does not have all bits set&quot;&lt;&lt; endl; &nbsp; &nbsp;} } int main() { &nbsp; &nbsp;bitset&lt;4&gt; bit1(string(&quot;1011&quot;)); &nbsp; &nbsp;bitset&lt;6&gt; bit2(string(&quot;111111&quot;)); &nbsp; &nbsp;cout&lt;&lt;&quot;The bitset is &quot;&lt;&lt;bit1&lt;&lt;endl; &nbsp; &nbsp;printer(bit1.all()); &nbsp; &nbsp;cout&lt;&lt;&quot;The bitset is &quot;&lt;&lt;bit2&lt;&lt;endl; &nbsp; &nbsp;printer(bit2.all()); &nbsp; &nbsp;return 0; }</pre><h2>Output</h2><pre class="result notranslate">The bitset is 1011 The bitset does not have all bits set The bitset is 111111 The bitset has all bits set</pre>
raja
Updated on 09-Aug-2019 12:21:03

Advertisements