jeudi 18 avril 2019

How can i erase element of VECTOR LIST in c++?

I need to erase the element of position 'k' in my code , Suppose i got the '3' in K so i wants to erase member of position 3 in vector list . What is the solution? thanks in advance !

#include <iostream>
#include <vector>
#include <bits/stdc++.h> 

using namespace std ;

int main() 
{ 
    vector<double> v1;
    vector <double>v2;
    double a ;
    for (int i=0;i<6;i++)
    {
        cout<<"Enter values :";
        cin>>a;

        v1.push_back(a);
    }
    cout<<endl;

    for (int i=0;i<6;i++)
    {
        for (int k=0;k<6;k++)
        {

                if (v1[i]==v1[k] && i!=k && k>i)
                {
                    cout<<"FOUND A REPEATING MEMBER IN VECTOR :"<<endl;
                    cout<<"repeating position: "<<k<<endl;
                    cout<<v1[k]<<endl;  
                    cout<<"ERASING MEMBER AT POSITION "<<k<<endl;
                    v1.erase(v1[k],v1.end());  //ERROR HERE!
                    cout<<"DONE"<<endl;
                }
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire