forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex17_10.cpp
More file actions
35 lines (28 loc) · 948 Bytes
/
ex17_10.cpp
File metadata and controls
35 lines (28 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/***************************************************************************
* @file main.cpp
* @author Alan.W
* @date 6 Mar 2014
* @remark This code is for the exercises from C++ Primer 5th Edition
* @note
***************************************************************************/
//!
//! Exercise 17.10:
//! Using the sequence 1, 2, 3, 5, 8, 13, 21, initialize a bitset that has a
//! 1 bit in each position corresponding to a number in this sequence. Default
//! initialize another bitset and write a small program to turn on each of the
//! appropriate bits.
//!
#include <iostream>
#include <bitset>
#include <vector>
int main()
{
std::vector<int> v = {1,2,3,5,8,13,21};
std::bitset<32> bset;
for (auto i : v) bset.set(i);
std::bitset<32> bset2;
for (unsigned i = 0; i != 32; ++i)
bset2[i] = bset[i];
std::cout <<bset <<std::endl;
std::cout <<bset2<<std::endl;
}