ccc

ccc
Last edited on
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 ?
Last edited on
Try this:
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <bitset>
#include <climits>
using namespace 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
Last edited on
b read for keyboard but no run. What is the code
Try the code above, it works without any input
Read B whit CIN
Dead integer for define number bits whit use CIN

I require read input , the number of bits to use ...
@zionet

Please re-edit your post and let other see it in future....

there will be other people in future who will someday find similar problem and could get help from your post
Original Topic Title: "Convert INT to BINARY with BITSET ERROR"

OP:

What is problem no read <b> b is a bits number

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <bitset>
using namespace std;

int main()
{
int b,x = 12;
cin>>b;
cout<< bitset<b> (x);
}
wow! did you remember all that stuff???
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/193018/
ooh!
Topic archived. No new replies allowed.