Why this is not working


and if we use
for(auto p:s)
{
cout<<p.first<<“and”<<p.second<<endl;
}
works good

Hey @guptanikhil898
Here

auto it=s.lower_bound(make_pair(20,1)); //it is an iterator
cout<<(*it).first<<","<<(*it).second<<endl; //to access iterator either dereference and use
cout<first<<","<second<<endl; //or like this (similar to what we do with pointers)

and here

for(auto p:s) //every p is a pair type
{
cout<<p.first<<“and”<<p.second<<endl;
}

for(set<pair<int,int>>::iterator it=s.begin();it!=s.end();it++)

{
    cout<<*(it).first<<"and"<<*(it).second<<endl;
}

why this is showing error

This should be (*it).first

and this (*it).second

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.