#include <bitset>
#include <assert.h>
#include <stdio.h>
using namespace std;
int main()
{
bitset<128> bs(42);
bs[11]=0;
bs[12]=1;
assert(bs[12]==1);
printf("bs[11]=%d\n", bs[11]);
printf("bs[12]=%d\n", bs[12]);
return 0;
}
Why can't I simply get 0 or 1 as output ?

printfwith%dis for integer values, whereasstd::bitset::operator[]returns astd::bitset::reference.You can use
std::coutfrom<iostream>header (which is anyway a more c++ "way" to print to the console):Output:
A side note: better to avoid
using namespace std- see here Why is "using namespace std;" considered bad practice?.