#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.