#include <iostream>
#include <bitset>
int main()
{
int x;
std::cin >> x;
std::bitset<8> bits(x);
std::cout << bits;
}
Now you turn it into a function and handle making sure the bitset is large enough; the size of bitset is fixed at compile time, so you might not like this method.
If you make the bitset 64 bits long, it will cover any input int you could type (assuming you're using a conventional PC). You could then turn it into a string (using the bitset class function to_string ) and then remove the leading zeroes to make it look pretty.