C++ <bitset> - size() Function
The C++ bitset::size function returns the number of bits in the bitset.
Syntax
size_t size() const;
constexpr size_t size() noexcept;
Parameters
No parameter is required.
Return Value
Number of bits present in the bitset.
Exception
Never throws exceptions.
Example:
In the example below, the bitset::size function is used to find out the number of bits in the given bitset.
#include <iostream> #include <bitset> using namespace std; int main (){ bitset<5> bset1; bitset<10> bset2; cout<<"bset1 contains "<<bset1.size()<<" bits.\n"; cout<<"bset2 contains "<<bset2.size()<<" bits.\n"; return 0; }
The output of the above code will be:
bset1 contains 5 bits. bset2 contains 10 bits.
❮ C++ <bitset> Library