c++ - Issues in searching through the vector? -


There is a vector in the form given to me (C ++):

  Vector & lt; Pair of & lt; Integer, integer & gt; & Gt; U;   

Now when the first element of u.first gets equal to 12 then I want to break with the loop. I am using the following code for this:

  while (1) {if ((search (u.begin) first, u.end (). First, 12)! = U.end ().)) {Break; }}   

However, it gives me an error

  'Unable to resolve the identifier first'    

std :: find iterates on a category and returns an iterator to the first element in the sequence which matches The provided value ( 12 , in your case), Iterators are not elements in the container, they are pseudo-references to the elements in the container.

In order to achieve the element you have to specify an error. Therefore, u.begin () - & gt; First will be the first value of the initial element of the container u.begin (). First is unnecessary.

In any case, to find a matching element using an operation other than == , you use find_if with a custom suspect For example, using the Lambda expression:

  Automatically interstate (std :: find_if (u.begin (), u.end (), [] (std :: Pair & lt; int, int & gt; bracket & v) {return v.first == 12;})); If (this! = U.end ()) continues;    

Comments