I am using a vector which has struct type of elements in it. The struct is something like this: Code: struct block { std::string id1; std::string id2; std::string last_line; }; The example value of id1 of first vector element is: id1 = 0001VVYF The example value of id2 of first vector element is: id2 = 0001VW1S AND The example value of id1 of second vector element is: id1 = 0001VW1S The example value of id2 of second vector element is: id2 = 0001VVYF i-e 1) the value of id1 of first vector element is equal to the value of id2 of second vector element 2) the value of id2 of first vector element is equal to the value of id1 of second vector element. In the program I have to find out whether the IDs of one vector element match the IDs of another vector element. I am not concerned about the id1 and id2. I am concerned about the values they hold in any order. It would be easier to compare if similar values appear against the same id e-g The example value of id1 of first vector element is: id1 = 0001VVYF The example value of id2 of first vector element is: id2 = 0001VW1S AND The example value of id1 of second vector element is: id2 = 0001VVYF The example value of id2 of second vector element is: id1 = 0001VW1S Is it possible to sort the vector this way i-e similar values appear against similar IDs?
You don't sort a vector, by definition it's an unsorted set. If you want a sorted set, you have to use a different container than a vector.