How can you tell if the vector bulleon has more than 2 digits true?

for (routeIterator4 = routes[i].begin(); routeIterator4 != routes[i].end(); routeIterator4++) { for (routeIterator7 = routes[j].begin(); routeIterator7 != routes[j].end(); routeIterator7++) { if (routeIterator4->x == routeIterator7->x) { visitedPoint[routeIterator7->x] = true; } } } if (visitedPoint[true] < 2) { for (routeIterator3 = routes[i].end() - 1; routeIterator3 != routes[i].begin(); routeIterator3--) { taker.x = routeIterator3->x; routes[j].push_back(taker); } } 

Then I want to check if more than 1 digit is true, I do not need to continue. Posted in this form, but does not work.

And the second question, if I enter the vector with end, why it does not take the very first digit, for example, I have a list of numbers 1,2,3,4,5,6,10 , it will take and add all the digits, except for one .. What could be the problem?

    1 answer 1

    It is somehow strangely written from the point of view of the Russian language. I did not fully understand the question, but I will try to answer, as I understood

    1) If you understand that you do not need to continue the cycle, then use the break; command break;

    2) The end() ) method returns an iterator pointing to the element following the last , not the last. That is, the iterator to the last element is - --end();

    • Alexey, I understand this perfectly and use the break method .. The question is that I cannot check how many digits are true ... Using if (visitedPoint [true] <2), it does not work as needed . - Misha Ostapchuk
    • The second question, I did not understand your answer .. Could you please indicate how to create a cycle so that it takes all the numbers into account? - Misha Ostapchuk
    • @MishaOstapchuk Aah, now I understand. check - cycle through the entire array, counting the number of true (or until you find 2, then break). In your case, in a nested loop in the if I would add 1 to some count variable, which shows the number of true - Alexey Sarovsky
    • @MishaOstapchuk about the second. If you need to go to the end, the cycle begins with - end (), and then the problem. For begin() in the general case, the decrement operation ( -- ) is not defined. The easiest way out of the cycle condition is to make at the end of his body. That is, add something like if(routeIterator3 == begin()) break; - Alexey Sarovsky
    • Thanks, this is a great idea and I apologize for the question that leads only to new questions .. The second question, I decided to use reverse, since I don’t know why it doesn’t take the first digit into account. Thank you so much - Misha Ostapchuk