Skip to content

Commit

Permalink
Merge pull request Mooophy#369 from sanshai/patch-1
Browse files Browse the repository at this point in the history
Update ex4_21.cpp
  • Loading branch information
Mooophy committed Nov 25, 2015
2 parents 84f844b + 0246cd0 commit 40b60e0
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions ch04/ex4_21.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#include <iostream>
#include <vector>

using std::cout;
using std::endl;
using std::vector;

int main()
{
std::vector<int> ivec{ 1, 2, 3, 4, 5, 6, 7, 8, 9 };
for (auto &i : ivec)
i = (i % 2) ? (i * 2) : i;

//Check
for (auto i : ivec)
std::cout << i << " ";
std::cout << std::endl;
vector<int> ivec{ 1, 2, 3, 4, 5, 6, 7, 8, 9 };

for (auto i : ivec) {
cout << ((i & 0x1) ? i * 2 : i) << " ";
}
cout << endl;

return 0;
}

0 comments on commit 40b60e0

Please sign in to comment.