samedi 10 avril 2021

Filling the array created by std::vector with an own function

I have a problem with a rather basic task. I am trying to fill an array by my own function and despite the impression that I'm doing everything ok, the fuction does not work.

So there is my fuction:

void fill_array(std::vector<int>arr ,int num)
{
    for (int i=0; i<num; i++)
    {
        std::cin>>arr[i];
    }
}

Which I then try to use like that:

std::vector<int>array(size);
fill_array(array, size);

But the array is not filling up. When I'm trying to look inside the array by f.e:

std::cout<<array[1];

The outcome is always 0.

How can I repair it? Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire