Skip to content

Commit 0246cd0

Browse files
committed
Update ex4_21.cpp
1 parent 84f844b commit 0246cd0

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

ch04/ex4_21.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
#include <iostream>
22
#include <vector>
33

4+
using std::cout;
5+
using std::endl;
6+
using std::vector;
7+
48
int main()
59
{
6-
std::vector<int> ivec{ 1, 2, 3, 4, 5, 6, 7, 8, 9 };
7-
for (auto &i : ivec)
8-
i = (i % 2) ? (i * 2) : i;
9-
10-
//Check
11-
for (auto i : ivec)
12-
std::cout << i << " ";
13-
std::cout << std::endl;
10+
vector<int> ivec{ 1, 2, 3, 4, 5, 6, 7, 8, 9 };
1411

12+
for (auto i : ivec) {
13+
cout << ((i & 0x1) ? i * 2 : i) << " ";
14+
}
15+
cout << endl;
16+
1517
return 0;
1618
}

0 commit comments

Comments
 (0)