How to insert a struct into a set in C++?

how to insert a struct into a set based on first element of the struct?

You can use set< pair<int,int> > if you want to store pair<int,int> in the set.