Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- void prn(int val) { std::cout << val << ' '; };
- int main()
- {
- std::vector<int> arr{ 1,2,3,4,5,6,7,8,9,10 };
- std::vector<int> arrB{10,20,30,40,50};
- //std::vector<float> arrF{ 1.1,2.2,3.3,4.3,5.5,6.6,7.7,8.8,9.8,10.1 };
- std::copy_if(arr.begin(), arr.end(), std::ostream_iterator<int>(std::cout, " "),
- [](const auto& el) { return (el % 2 == 0); });
- std::cout << "\narrB pre copy\n";
- //std::for_each(arrB.begin(), arrB.end(), [](const auto& val) { std::cout << val << ' '; });
- std::copy(arrB.begin(), arrB.end(), std::ostream_iterator<int>(std::cout, " "));
- std::copy_if(arr.begin(), arr.end(), std::inserter(arrB, std::next(arrB.begin(), 3)),
- [](const auto& el) { return (el % 2); });
- std::cout << "\narrB post copy\n";
- //std::for_each(arrB.begin(), arrB.end(), [](const auto& val) { std::cout << val << ' '; });
- std::copy(arrB.begin(), arrB.end(), std::ostream_iterator<int>(std::cout, " "));
- return 0;
- //for (int i{ 0 }; i < arr.size(); ++i)
- //{
- // std::cout << arr[i] << ' ';
- //}
- //std::cout << '\n';
- //for (int cnt{0}; const auto& el : arr)
- //{
- // std::cout << cnt++ << " = " << el << '\n';
- //}
- //for (auto it{ std::next(arr.begin(),1) }; it != std::prev(arr.end(),2); ++it)
- //{
- // std::cout << std::distance(arr.begin(), it) << ' ' << *it << '\n';
- //}
- //std::cout << '\n';
- int mul{ 2 };
- auto print = [](const auto& val) {std::cout << val << ' '; };
- std::for_each(std::next(arr.begin(), 2), std::prev(arr.end(), 2), [mul](auto& val) { val *= mul; std::cout << val << ' '; });
- //std::for_each(arr.begin(), arr.end(), print);
- std::cout << '\n';
- //std::for_each(arrF.begin(), arrF.end(), print);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement