Im doing an task atm. which I should compare all of the vector elements in an given range, in two different vector, for almost equal with help of STL algorithm.
Almost equal in this situation: 2.
Anyone know an solution for this problem?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you want less-than comparison, use std::lexicographical_compare with a custom comparator implementing whatever it is that almost equal means for you.
If you want equality comparison, use std::equal, as pointed out in the comments:
This is a simplified comparison function to show how to use the algorithm, you would have to decide what to do if the vectors have different length.