Your question on how to accomplish this with scanf
and printf
seems to be an XY problem. The answer provided by @GSliepen shows you how to do it properly in C++.
However, in case you are really interested on how to accomplish this using scanf
and printf
(which I don't recommend), I will give you a direct answer to your question:
You cannot use scanf
directly with bitsets, because scanf
requires an address to at least a byte, not a single bit. Addresses to single bits don't even exist (at least on most platforms). However, you can first use scanf
to write to a temporary byte (unsigned char
) or an int
and then convert it to a bit for the bitset, for example like this:
#include <bitset>
#include <cstdio>
#include <cassert>
int main()
{
std::bitset<1> aoeu;
int ret, input;
ret = std::scanf( "%d", &input );
assert( ret == 1 );
aoeu[0] = input;
std::printf( "%d\n", static_cast<int>(aoeu[0]) );
}
In case you are wondering why I am not using namespace std;
, although you do in your question, then you may want to read this StackOverflow question.