Bitset Exercise from C++ Primer

Write your question here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <bitset>

using std::cin;
using std::cout;
using std::endl;
using std::bitset;

int main(){
	bitset<32> bitvec, bitvec2;

	while (cin >> bitvec){
		for (int index = 0; index != bitvec.size(); index++)
			if (bitvec.test(index))
				if (!bitvec2.test(index))
					bitvec2.set(index);
	}
	cout << bitvec2 << endl;
	cin.get();
	return 0;
}


My C++ Primer book has an exercise, that says "Consider the sequence 1,2,3,5,8,13,21. Initialize a bitset<32> that has a one bit in each position corresponding to a number in this sequence. Alternatively, given an empty bitset, write a small program to turn on each of the appropriate bits."

I wrote this program, but after inputting the second number, it prints out a bitset, and then quits. I'm not sure what's wrong. Thanks for any help.
Line 12. What input can be converted into bitset<32>?
Topic archived. No new replies allowed.