Template parameters must be compile-time constants. Think of a template as a code generator: The code has to be generated before you start compiling. You cannot use templates "at runtime"!
const unsigned int size = 10;
std::bitset<size> b; // fine, the compiler knows what "size is"
unsigned int n; cin >> n;
std::bitset<n> c; // doesn't make sense!
As a first step you should say const
as much as possible in your code; it's possible that you actually do have compile-time constants but aren't declaring them as such.
If you really need a data structure with dynamic size, you need to use something else (e.g. a vector of unsigned chars along with a bitwise accessor function).
Here's a very simple implementation of a bit set as a vector of chars. I'm not wrapping this in a class, you can do that if that's needed:
std::vector<unsigned char> data;
bool getBit(size_t n, const std::vector<unsigned char> & data)
{
if (data.size() * CHAR_BIT) <= n) return 0;
return data[n / CHAR_BIT] & (1U << (n % CHAR_BIT));
}
void setBit(size_t n, std::vector<unsigned char> & data)
{
if (data.size() * CHAR_BIT) <= n) data.resize(n / CHAR_BIT + 1, 0);
data[n / CHAR_BIT] |= (1U << (n % CHAR_BIT));
}
// Exercise for the reader
void clrBit(size_t n, std::vector<unsigned char> & data);
void tglBit(size_t n, std::vector<unsigned char> & data);