Jul 17, 2013 at 5:43pm UTC
How do I set a bitset to be equal to another bitset? Say I have a bitset<3> mybits1(string "010"), how do I set bitset<3> mybits2 to be equal to mybits1 without going through each bit?
Jul 17, 2013 at 5:52pm UTC
Did you try to use simply the assignment operator?
mybits2 = mybits1;
For example
1 2 3 4 5 6 7 8 9 10 11 12
#include <iostream>
#include <bitset>
int main()
{
std::bitset<3> b1( "101" );
std::bitset<3> b2;
b2 = b1;
std::cout << b2 << std::endl;
}
Last edited on Jul 17, 2013 at 5:57pm UTC
Jul 17, 2013 at 7:23pm UTC
Yeah it works. I guess my problem is when b1 is declared in another file, say a header file.
Jul 17, 2013 at 7:26pm UTC
I know nothing how and where you declare objects.
Jul 17, 2013 at 7:28pm UTC
Thank you.
My problem was I have two bitsets of different sizes.