- #include <iostream>
- #include <bitset>
- using namespace std;
- #define Print(bit) cout << bit.to_string<char, char_traits<char>, allocator<char> >() << endl
- int main(int argc, char *argv[])
- {
- bitset<4> bit;
- Print(bit);
- bool Flag = 1;
- int i;
- while (true)
- {
- if (Flag)
- {
- bit.flip(0);
- }
- else
- {
- for (i = 0; !bit.test(i) && i < bit.size(); ++i);
- if (i == bit.size() - 1)
- {
- break;
- }
- else
- {
- bit.flip(i + 1);
- }
- }
- Print(bit);
- Flag = !Flag;
- }
- return 0;
- }