1auto int_bits_size = 32; // maximum number of bits for the integer
2auto some_integer = 123456789;
3std::string str = std::bitset<int_bits_size>(some_integer).to_string();
1 ==== Convert number to binary string C++ ======
2 int n = 100;
3 string s1=""
4//Method 1:
5 string s1 = bitset<8>(n).to_string(); // 01100100
6//Method 2
7 while(n) {
8 s1 += (n%2) + '0';
9 n /= 2;
10 }
11 reverse(s1.begin(),s1.end()); // 1100100