The template argument needs to be a compile time constant, whereas in this case, b is a variable.
Why not just set the size to be sizeof(int)*CHAR_BIT ?
#include <iostream>
#include <bitset>
#include <climits>
usingnamespace std;
int main()
{
int x = 12;
cout << bitset<sizeof(int)*CHAR_BIT> (x);
}
EDIT: If you want to remove the preceding zeroes, you could use a stringstream to convert a bitset to a string, then use find the first 1 and truncate the string with substr