how to get the value of Nth element of set directly
#include <bits/stdc++.h>
using namespace std;
int main(){
set<int> a;
a.insert(1);
a.insert(2);
a.insert(3);
a.insert(4);
a.insert(5);
cout << ans[4] << endl;
}
I want '4' as an output without iterating over a loop 4 times with iterator. Is there a pre-defined way to get nth element of a set.
" error: no match for ‘operator[]’ (operand types are ‘std::set’ and ‘int’)"