I am trying to write this code but this is giving the error
No matching member function for call to 'erase'clang(ovl_no_viable_member_function_in_call)
stl_vector.h(1317, 7): Candidate function not viable: no known conversion from 'int' to 'std::vector<int, std::allocator<int> >::const_iterator' (aka '__normal_iterator<const int *, std::vector<int, std::allocator<int> > >') for 1st argument
stl_vector.h(1344, 7): Candidate function not viable: requires 2 arguments, but 1 was provided
Here is my Code
#include <iostream>
#include <vector>
using namespace std;
int sockMerchant(int n, vector<int> ar) {
int pairCount=0;
for(int i=0;i<ar.size();i++)
{
for(int j=i+1;j<ar.size();j++)
{
if(ar[i]==ar[j])
pairCount++;
ar.erase(j);
}
}
return pairCount;
}
int main()
{
int n;
cin>>n;
vector <int> arr;
for(int i=0;i<n;i++)
{
int e=0;
cin>>e;
arr.push_back(e);
}
sockMerchant(n, arr);
}
Also if you can, please tell me why am I getting this error as I followed the same approach of erase function as it was done in gfg.