Bitset equals another bitset

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?
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
Yeah it works. I guess my problem is when b1 is declared in another file, say a header file.
I know nothing how and where you declare objects.
Thank you.
My problem was I have two bitsets of different sizes.
Topic archived. No new replies allowed.