cant use vector erase?

I am trying to use the erase function belonging to vector, but I am getting errors and I can not figure out why. I am getting different errors for it, but the ones i can understand dont make any sense, like no member function, or passing the wrong amount of arguments, I only want to pass the one argument.

errors are :
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  #include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {

    
    int firstInt {};
    vector <int> v {};
    int vecInts {};
    int rangeFirst {};
    int rangeSecond {};
    
    cin >> firstInt;
    
    while (cin >> vecInts)
    {
        v.push_back(vecInts);
    }
    
    v.erase(firstInt);
    
    for (auto n : v)
    {
        cout << n << " ";
    }
    
    return 0;
}
https://www.cplusplus.com/reference/vector/vector/erase/
erase has two overloads. One taking in a single iterator, and another taking in a beginning and end iterator.

If you want to have it find a particular integer to erase, you have to combine it with std::find.
https://www.cplusplus.com/reference/algorithm/find/

If you want to have it find a particular integer to erase, you have to combine it with std::find.


Thank you, i just remembered that, for some reason when i spend more than a week away from going over stuff, I completely forget it.
> If you want to have it find a particular integer to erase, you have to combine it with std::find

C++20 has std::erase which erases elements that compare equal to a value from a container.
for vector: https://en.cppreference.com/w/cpp/container/vector/erase2
That is much more succinct, thanks.
Topic archived. No new replies allowed.