Hi I have just started learning c++ and i cant seem to make out why this code is giving me a runtime exception while converting a vector to set and set to vector. Please Help!
#include <bits/stdc++.h>
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> v;
for(int i = 0; i < n; i++) { cin >> v[i]; }
set<int> s(v.begin(), v.end());
vector<int> v2(s.begin(), s.end());
if (v2.size() >= 2)
cout << v2[1];
else
cout << "NO";
return 0;
}