I'm trying to find the position of an element in a vector and then assigning it to a variable but for some reason its not working.
Here I am using vector.at() as was used by someone doing the same thing here on this site. However when I use it in my case all its returning is the actual element itself instead of the position.
Here is my loop. It is designed to loop though the vector to find the highest value and assign it to a variable(this woks) max and its position to a variable pos but this does not work.
for (int i = 0; i <= people.size(); ++i) {
if (people[i] > max) {
max = people[i];
pos = people.at(i);
}
}
people is my < int > vector.
Aucun commentaire:
Enregistrer un commentaire