S.1. Bitsets
As introduced in Section 12.5, page 650, bitsets model fixed-sized arrays of bits or Boolean values and are useful for managing sets of flags, where variables may represent any combination of flags. C and old C++ programs usually use type long
for arrays of bits and manipulate them with the bit operators, such as &, |, and ~. The class bitset
has the advantage that bitsets may contain any number of bits, and additional operations are provided. For example, you can assign single bits and can read and write bitsets as a sequence of 0
sand 1
s.
Note that you can’t change the number of bits in a bitset. The number of bits is the template parameter. If you need a container for a variable number of bits or Boolean values, you can use the ...
Get C++ Standard Library, The: A Tutorial and Reference, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.