c++ - Issues of getting stuck into infinite loop while iterating through vectors -


I want to search with a vector of joints and to do this ... I am doing the following:

  vector and lieutenant; Pair and lieutenant; Double, double & gt; & Gt; Vec_pairs; For (vector and lieutenant; unsigned interval; :: size_ type j = 0; j! = Vec_pairs.size (); j ++) {if (vec_pairs [j]. First == 12.6) {int z = 7; to continue; }}   

However my problem is ... on doing this ... I'm stuck in an infinite loop ... can help me solve any problem < First of all, the code posted by you is like 'OK'.

The only reason for going into an infinite loop for this kind of code is to modify the j inside the loop.

If you rise j inside the loop, you probably will not be trapped because you will exit the bond and your code may crash.

 for  (vector and lieutenant; unsigned interval; :: size_type j = 0; j! = Vec_pairs.size (); j ++) {if (vec_pairs [j] .first = = 12.6) {j ++; // You will go out of vector bonds and get an error here. to continue; }}   

However, if you do something like this:

 for  (vector = lieutenant; unsigned int gt; :: size_type j = 0; J! = Vec_pairs .size (); j ++) {if (vec_pairs [j] .first == 12.6) Every time you receive it here, you will get stuck on an element every time, continue; }}   

Then you will be stuck inside, because when you go into the if statement (say, on element 7), j 6 will decrease, then you will increase in continue loop, j 7, if you go inside if , and expeditiously.

Comments