what does copy if c 2b 2b

Solutions on MaxInterview for what does copy if c 2b 2b by the best coders in the world

showing results for - "what does copy if c 2b 2b"
Veronica
18 Nov 2018
1//C++ STL program to demonstrate use of
2//std::copy_if() function
3#include <iostream>
4#include <algorithm>
5#include <vector>
6using namespace std;
7
8int main()
9{
10    //declaring & initializing an int array
11    int arr[] = { 10, 20, 30, -10, -20, 40, 50 };
12    //vector declaration
13    vector<int> v1(7);
14
15    //copying 5 array elements to the vector
16    copy_if(arr, arr + 7, v1.begin(), [](int i) { return (i >= 0); });
17
18    //printing array
19    cout << "arr: ";
20    for (int x : arr)
21        cout << x << " ";
22    cout << endl;
23
24    //printing vector
25    cout << "v1: ";
26    for (int x : v1)
27        cout << x << " ";
28    cout << endl;
29
30    return 0;
31}
32