What you are looking for is a dynamic_bitset
. It is like std::bitset
but it can change its size dynamically.
Also, you can use std::vector<bool>
which will do what you need as a side effect of slightly unfortunate historical decision to implement it as a bitset.
Hope it helps. Good Luck!