 # Check two points are equal.

How to check two points are equal using C++ STL?
Input :
0, 0
0, 0

Output :
Yes

Why you want this question from STL? It can simply be perform by if-else condition.

1 Like

Suppose you have two points as pair<int,int> .

p1,p2 are the two points,then you write

cout<<((p1==p2)?“YES”:“NO”);

Remember to enclose (p1==p2)?“YES”:“NO” in parentheses as conditional operator have least precedence.

So cout<<((p1==p2)?“YES”:“NO”); can get your job done.

Hope it helps…

1 Like

Vector V represent a pair inside Vector, so V.first represent the first element and V.second represent the second element of V. Same case are applying on V. So i compare condition you are just comparing both these value of vector- (V, V) by simply if condition.

As pointed out by others, you don’t need to use STL here. Normal comparison operation will do.

But since you ask specifically for using C++ STL, refer to http://www.cplusplus.com/reference/functional/equal_to/

Declare an object of equal_to of appropriate type (pair< int, int > here). Let it be f. Just call f(V, V).

Here is an example - http://ideone.com/TlXFZG

1 Like

I tried to implement this code :

But here No STL are used. Only if else are used

But how???