C++ Bitset Library - set() Function



Description

The C++ function std::bitset::size() Reports the size of the bitset.

Declaration

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

C++98

size_t size() const;

C++11

constexpr size_t size() noexcept;

Parameters

None

Return value

Returns the number of element present in the bitset.

Exceptions

This member function never throws exception.

Example

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

#include <iostream>
#include <bitset>

using namespace std;

int main(void) {

   bitset<4> b;

   cout << "Bitset contains " << b.size() << " bits." << endl;

   return 0;
}

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

Bitset contains 4 bits.
bitset.htm
Advertisements