C++ Bitset Library - set() Function



Description

The C++ function std::bitset::set() set all bits from bitset to one.

Declaration

Following is the declaration for std::bitset::set() function form std::bitset header.

C++98

 bitset& set(); 

C++11

 bitset& set() constexpr; 

Parameters

None

Return value

Returns this pointer.

Exceptions

This member function never throws exception.

Example

The following example shows the usage of std::bitset::set() function.

 #include <iostream> #include <bitset> using namespace std; int main(void) { bitset<4> b; cout << "Before set operation b = " << b << endl; b.set(); cout << "After set operation b = " << b << endl; return 0; } 

Let us compile and run the above program, this will produce the following result −

 Before set operation b = 0000 After set operation b = 1111 
bitset.htm
Advertisements