mercredi 30 octobre 2019

How to iterate through range based for loop with variable end point

I'm trying to use a range based for loop to iterate from the beginning of a vector to a variable destination x as shown.

void algorithm(vector<int>, int n)
{
int count=0;
for (int i:arr[n])
count++;
}

I understand the above function is rather useless but I'm trying to conceptually understand if there is a way to do so. arr[n] gives me an error as does arr.begin()+n

Aucun commentaire:

Enregistrer un commentaire