Answers for "vector assign"

C++
5

convert set to vector c++

#include <set>
#include <vector>

std::vector<int> some_vector(some_set.begin(), some_set.end());
Posted by: Guest on September-15-2020
0

vector assign

#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int arr[] = {1, 2, 3, 4, 7};
    vector<int> v1;
    vector<int> v2;
    v1.assign(arr, arr+5);
    v2.assign(arr, arr+2);

    //printing values of v1
    cout << "elements of v1" << endl;
    for(int i = 0; i < v1.size(); i++)
    {
        cout << v1[i] << endl;
    }

    //printing values of v2
    cout << "elements of v2" << endl;
    for(int i = 0; i < v2.size(); i++)
    {
        cout << v2[i] << endl;
    }
    return 0;
}
Posted by: Guest on June-27-2021

Browse Popular Code Answers by Language