John Smith
John Smith

Reputation: 12236

Trying to remove an element from a vector by value

error: cannot convert 'std::vector<int>::iterator {aka __gnu_cxx::__normal_iterator<int*, std::vector<int> >}' to 'const char*' for argument '1' to 'int remove(const char*)

When I am doing

vec.erase(std::remove(vec.begin(), vec.end(), valToRemove), vec.end());

valToRemove is an int.

Upvotes: 2

Views: 2183

Answers (1)

Ivan Smirnov
Ivan Smirnov

Reputation: 4435

You were most likely trying to call this function instead the correct one. Probably you don't have <algorithm> included so the compiler can't see the overloaded version of the function.

Upvotes: 15

Related Questions