Jun 18, 2016 at 5:17am Jun 18, 2016 at 5:17am UTC
ccc
Last edited on Jun 18, 2016 at 10:45pm Jun 18, 2016 at 10:45pm UTC
Jun 18, 2016 at 5:24am Jun 18, 2016 at 5:24am UTC
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 Jun 18, 2016 at 5:26am Jun 18, 2016 at 5:26am UTC
Jun 18, 2016 at 5:28am Jun 18, 2016 at 5:28am UTC
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 Jun 18, 2016 at 5:32am Jun 18, 2016 at 5:32am UTC
Jun 18, 2016 at 5:29am Jun 18, 2016 at 5:29am UTC
b read for keyboard but no run. What is the code
Jun 18, 2016 at 5:33am Jun 18, 2016 at 5:33am UTC
Try the code above, it works without any input
Jun 18, 2016 at 5:40am Jun 18, 2016 at 5:40am UTC
Dead integer for define number bits whit use CIN
Jun 18, 2016 at 5:42am Jun 18, 2016 at 5:42am UTC
I require read input , the number of bits to use ...
Jun 19, 2016 at 8:04am Jun 19, 2016 at 8:04am UTC
@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
Jun 20, 2016 at 3:40am Jun 20, 2016 at 3:40am UTC
wow! did you remember all that stuff???
Jun 20, 2016 at 3:42am Jun 20, 2016 at 3:42am UTC
http://www.cplusplus.com/forum/beginner/193018/