S.Mitchell S.Mitchell - 15 days ago 5
C++ Question

should I use a bit set or a vector? C++

I need to be able to store an array of binary numbers in c++ which will be passed through different methods and eventually outputted to file and terminal,

What are the key differences between vectors and bit sets and which would be easiest and/or more efficient to use?

(I do not know how many bits I need to store)

Answer

It all depends on what you want to do binary.

You could also use boost.dynamic_bitset which is like std::bitset but not with fixed bits. The main drawback is dependency on boost if don't already use it.

You could also store your input in std::vector<char> and use a bitset per char to convert binary notation.

As other already told: std::bitset uses a fixed number of bits.

std::vector<bool> is not always advised because it has it quirks as it is not a real container (gotw)