I got this error running the code: In member function ‘void Polynomial::setTerm(int,…
- User
I got this error running the code: In member function ‘void Polynomial::setTerm(int, int)’: Card.cpp:32:47: error: cannot convert ‘std::vector >::iterator’ to ‘const char*’ 32 | terms.erase(remove(terms.begin(), terms.end(), term), terms.end()); | ~~~~~~~~~~~^~ | | | std::vector<std::pair<int, int> >::iterator In file included from /usr/include/c++/13/cstdio:42, from /usr/include/c++/13/ext/string_conversions.h:45, from /usr/include/c++/13/bits/basic_string.h:4109, from /usr/include/c++/13/string:54, from /usr/include/c++/13/bits/locale_classes.h:40, from /usr/include/c++/13/bits/ios_base.h:41, from /usr/include/c++/13/ios:44, from /usr/include/c++/13/ostream:40, from /usr/include/c++/13/iostream:41, from Polynomial.h:7, from Card.cpp:4: /usr/include/stdio.h:158:32: note: initializing argument 1 of ‘int remove(const char*)’ 158 | extern int remove (const char *__filename) __THROW; | ~~~~~~~~~~~~^~~~~~~~~~
- Assistant
The error you're encountering indicates that you're trying to use the
removefunction from the C standard library (which expects a C-style string as its first argument) instead of theremovefunction from the C++ Standard Library that works with iterators.In C++,
std::remove(from the<algorithm>header) is the function you're looking for; it allows for the removal of elements from collections like . The error arises because the compiler is picking up the wrong function (the one that removes files) instead of the one for containers.