0
Finding the position of value in Vector
The goal of this task is to write a function such that when two favorite nos X and Y are entered alongside array, we check the number of instances for which X and Y occur equally and then return the A[equal] position after which the two numbers entered are no longer equal. In my attempt the function returns 1 instead of 4 which is the position. How can I correct this and please i want to use the auto for looping the vector. https://code.sololearn.com/cZzV7RLNQ2aq
3 odpowiedzi
0
Just subtract begin() from the current position of the iterator to get the actual index and then store it in *result*. ( You can also use "std::distance(A.begin(), i)" for the same )
Here's the fix 👇
https://code.sololearn.com/cQlRhuFGvf9Y/?ref=app
0
Jay Matthews i ran it with that but im still getting compiler errors
0
Arsenic super it works. Just one more question, does this always work whenever we want to vector indexes when looping through them using auto method?